[PATCH] D67463: [MS] Warn when shadowing template parameters under -fms-compatibility

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 12 11:26:20 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL371753: [MS] Warn when shadowing template parameters under -fms-compatibility (authored by rnk, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67463?vs=219780&id=219956#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67463/new/

https://reviews.llvm.org/D67463

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
  cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp


Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -849,15 +849,14 @@
 void Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl) {
   assert(PrevDecl->isTemplateParameter() && "Not a template parameter");
 
-  // Microsoft Visual C++ permits template parameters to be shadowed.
-  if (getLangOpts().MicrosoftExt)
-    return;
-
   // C++ [temp.local]p4:
   //   A template-parameter shall not be redeclared within its
   //   scope (including nested scopes).
-  Diag(Loc, diag::err_template_param_shadow)
-    << cast<NamedDecl>(PrevDecl)->getDeclName();
+  //
+  // Make this a warning when MSVC compatibility is requested.
+  unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
+                                             : diag::err_template_param_shadow;
+  Diag(Loc, DiagId) << cast<NamedDecl>(PrevDecl)->getDeclName();
   Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4000,6 +4000,8 @@
 // C++ Template Declarations
 def err_template_param_shadow : Error<
   "declaration of %0 shadows template parameter">;
+def ext_template_param_shadow : ExtWarn<
+  err_template_param_shadow.Text>, InGroup<MicrosoftTemplate>;
 def note_template_param_here : Note<"template parameter is declared here">;
 def warn_template_export_unsupported : Warning<
   "exported templates are unsupported">;
Index: cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
+++ cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
@@ -366,3 +366,21 @@
 int S::fn() { return 0; } // expected-warning {{is missing exception specification}}
 }
 
+namespace PR43265 {
+template <int N> // expected-note {{template parameter is declared here}}
+struct Foo {
+  static const int N = 42; // expected-warning {{declaration of 'N' shadows template parameter}}
+};
+}
+
+namespace Inner_Outer_same_template_param_name {
+template <typename T> // expected-note {{template parameter is declared here}}
+struct Outmost {
+  template <typename T> // expected-warning {{declaration of 'T' shadows template parameter}}
+  struct Inner {
+    void f() {
+      T *var;
+    }
+  };
+};
+}
Index: cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
===================================================================
--- cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
+++ cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
@@ -48,22 +48,6 @@
 
               
 
-namespace Inner_Outer_same_template_param_name {              
-
-template <class T>
-class Outmost {
-public:
-    template <class T>
-    class Inner {
-    public:
-        void f() {
-            T* var;
-        }
-   };
-};
-
-}
-
 
 namespace PR11931 {
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67463.219956.patch
Type: text/x-patch
Size: 3153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190912/f6b0a5c7/attachment-0001.bin>


More information about the cfe-commits mailing list