From d9974190c26c0ee9d8e1a8e6b569b2c89e9885b3 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 17 Apr 2014 02:56:49 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206441 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 12 ++++----- test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp | 8 +++--- test/SemaCXX/cxx98-compat.cpp | 36 +++---------------------- 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 13725dc3f3..fb2049f6ea 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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); } } } diff --git a/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp b/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp index 41ff3e2823..1d04d7d2a7 100644 --- a/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp +++ b/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp @@ -65,8 +65,8 @@ namespace inline_namespaces { template<> void ft() {} template void ft(); // expected-error {{undefined}} - template int mt; // expected-warning {{extension}} - template<> int mt; // expected-warning {{extension}} + template int mt; + template<> int mt; template int mt; template int mt; // expected-error {{undefined}} @@ -92,8 +92,8 @@ namespace inline_namespaces { template<> void N::gt() {} template void N::gt(); // expected-error {{undefined}} - template int N::nt; // expected-warning {{extension}} - template<> int N::nt; // expected-warning {{extension}} + template int N::nt; + template<> int N::nt; template int N::nt; template int N::nt; // expected-error {{undefined}} diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index 8c1efc9672..96af95425a 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -379,38 +379,22 @@ template 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 T* var = 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 = 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; float fvar = var; -class A { +class A { template 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 static T* var = 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 static T* var = new T(); }; struct B { template static T v; }; @@ -428,19 +412,7 @@ template T B::v = T(); #endif template T* B::v = 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 = 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; float fsvar = B::v; -- 2.40.0