r206441 - Don't emit an ExtWarn on declarations of variable template specializations;

Richard Smith richard-llvm at metafoo.co.uk
Wed Apr 16 19:56:49 PDT 2014


Author: rsmith
Date: Wed Apr 16 21:56:49 2014
New Revision: 206441

URL: http://llvm.org/viewvc/llvm-project?rev=206441&view=rev
Log:
Don't emit an ExtWarn on declarations of variable template specializations;
we'll already have issued the relevant diagnostic when we saw the declaration
of the primary template.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
    cfe/trunk/test/SemaCXX/cxx98-compat.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=206441&r1=206440&r2=206441&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr 16 21:56:49 2014
@@ -5263,12 +5263,6 @@ Sema::ActOnVariableDeclarator(Scope *S,
                          TemplateParams->getRAngleLoc());
         TemplateParams = 0;
       } else {
-        // Only C++1y supports variable templates (N3651).
-        Diag(D.getIdentifierLoc(),
-             getLangOpts().CPlusPlus1y
-                 ? diag::warn_cxx11_compat_variable_template
-                 : diag::ext_variable_template);
-
         if (D.getName().getKind() == UnqualifiedId::IK_TemplateId) {
           // This is an explicit specialization or a partial specialization.
           // FIXME: Check that we can declare a specialization here.
@@ -5281,6 +5275,12 @@ Sema::ActOnVariableDeclarator(Scope *S,
           // Check that we can declare a template here.
           if (CheckTemplateDeclScope(S, TemplateParams))
             return 0;
+
+          // Only C++1y supports variable templates (N3651).
+          Diag(D.getIdentifierLoc(),
+               getLangOpts().CPlusPlus1y
+                   ? diag::warn_cxx11_compat_variable_template
+                   : diag::ext_variable_template);
         }
       }
     }

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp?rev=206441&r1=206440&r2=206441&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp Wed Apr 16 21:56:49 2014
@@ -65,8 +65,8 @@ namespace inline_namespaces {
     template<> void ft<int>() {}
     template void ft<char>(); // expected-error {{undefined}}
 
-    template<typename T> int mt<T*>; // expected-warning {{extension}}
-    template<> int mt<int>; // expected-warning {{extension}}
+    template<typename T> int mt<T*>;
+    template<> int mt<int>;
     template int mt<int*>;
     template int mt<char>; // expected-error {{undefined}}
 
@@ -92,8 +92,8 @@ namespace inline_namespaces {
   template<> void N::gt<int>() {}
   template void N::gt<char>(); // expected-error {{undefined}}
 
-  template<typename T> int N::nt<T*>; // expected-warning {{extension}}
-  template<> int N::nt<int>; // expected-warning {{extension}}
+  template<typename T> int N::nt<T*>;
+  template<> int N::nt<int>;
   template int N::nt<int*>;
   template int N::nt<char>; // expected-error {{undefined}}
 

Modified: cfe/trunk/test/SemaCXX/cxx98-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx98-compat.cpp?rev=206441&r1=206440&r2=206441&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx98-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx98-compat.cpp Wed Apr 16 21:56:49 2014
@@ -379,38 +379,22 @@ template<typename T> T var = T(10);
 // expected-warning at -4 {{variable templates are a C++1y extension}}
 #endif
 
+// No diagnostic for specializations of variable templates; we will have
+// diagnosed the primary template.
 template<typename T> T* var<T*> = new T();
-#ifdef CXX1YCOMPAT
-// expected-warning at -2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning at -4 {{variable templates are a C++1y extension}}
-#endif
-
 template<> int var<int> = 10;
-#ifdef CXX1YCOMPAT
-// expected-warning at -2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning at -4 {{variable templates are a C++1y extension}}
-#endif
-
 template int var<int>;
 float fvar = var<float>;
 
-class A {  
+class A {
   template<typename T> static T var = T(10);
 #ifdef CXX1YCOMPAT
 // expected-warning at -2 {{variable templates are incompatible with C++ standards before C++1y}}
 #else
 // expected-warning at -4 {{variable templates are a C++1y extension}}
 #endif
-  
-  template<typename T> static T* var<T*> = new T(); 
-#ifdef CXX1YCOMPAT
-// expected-warning at -2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning at -4 {{variable templates are a C++1y extension}}
-#endif
 
+  template<typename T> static T* var<T*> = new T(); 
 };
 
 struct B {  template<typename T> static T v; };
@@ -428,19 +412,7 @@ template<typename T> T B::v = T();
 #endif
 
 template<typename T> T* B::v<T*> = new T();
-#ifdef CXX1YCOMPAT
-// expected-warning at -2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning at -4 {{variable templates are a C++1y extension}}
-#endif
-
 template<> int B::v<int> = 10;
-#ifdef CXX1YCOMPAT
-// expected-warning at -2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning at -4 {{variable templates are a C++1y extension}}
-#endif
-
 template int B::v<int>;
 float fsvar = B::v<float>;
 





More information about the cfe-commits mailing list