]> granicus.if.org Git - clang/commitdiff
Don't emit an ExtWarn on declarations of variable template specializations;
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 17 Apr 2014 02:56:49 +0000 (02:56 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 17 Apr 2014 02:56:49 +0000 (02:56 +0000)
we'll already have issued the relevant diagnostic when we saw the declaration
of the primary template.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206441 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 13725dc3f390fdd792023db6c0990286f1a60f87..fb2049f6eae16470b3ac30e018f82f6daa4bfe7b 100644 (file)
@@ -5263,12 +5263,6 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
                          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, Declarator &D, DeclContext *DC,
           // 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);
         }
       }
     }
index 41ff3e28237106807c5e3f6d0d0e226319b236ed..1d04d7d2a7005e968ddeb5beaf67e864d0a6cb36 100644 (file)
@@ -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}}
 
index 8c1efc967281821a59d0c2e04f2de978a488f4dd..96af95425aecce8b3826627ac2001237d61ea2db 100644 (file)
@@ -379,38 +379,22 @@ template<typename T> T var = T(10);
 // expected-warning@-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@-2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning@-4 {{variable templates are a C++1y extension}}
-#endif
-
 template<> int var<int> = 10;
-#ifdef CXX1YCOMPAT
-// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning@-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@-2 {{variable templates are incompatible with C++ standards before C++1y}}
 #else
 // expected-warning@-4 {{variable templates are a C++1y extension}}
-#endif
-  
-  template<typename T> static T* var<T*> = new T(); 
-#ifdef CXX1YCOMPAT
-// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning@-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@-2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning@-4 {{variable templates are a C++1y extension}}
-#endif
-
 template<> int B::v<int> = 10;
-#ifdef CXX1YCOMPAT
-// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
-#else
-// expected-warning@-4 {{variable templates are a C++1y extension}}
-#endif
-
 template int B::v<int>;
 float fsvar = B::v<float>;