Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit d997419

Browse files
committed
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
1 parent 46d5a26 commit d997419

File tree

3 files changed

+14
-42
lines changed

3 files changed

+14
-42
lines changed

lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5263,12 +5263,6 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
52635263
TemplateParams->getRAngleLoc());
52645264
TemplateParams = 0;
52655265
} else {
5266-
// Only C++1y supports variable templates (N3651).
5267-
Diag(D.getIdentifierLoc(),
5268-
getLangOpts().CPlusPlus1y
5269-
? diag::warn_cxx11_compat_variable_template
5270-
: diag::ext_variable_template);
5271-
52725266
if (D.getName().getKind() == UnqualifiedId::IK_TemplateId) {
52735267
// This is an explicit specialization or a partial specialization.
52745268
// FIXME: Check that we can declare a specialization here.
@@ -5281,6 +5275,12 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
52815275
// Check that we can declare a template here.
52825276
if (CheckTemplateDeclScope(S, TemplateParams))
52835277
return 0;
5278+
5279+
// Only C++1y supports variable templates (N3651).
5280+
Diag(D.getIdentifierLoc(),
5281+
getLangOpts().CPlusPlus1y
5282+
? diag::warn_cxx11_compat_variable_template
5283+
: diag::ext_variable_template);
52845284
}
52855285
}
52865286
}

test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ namespace inline_namespaces {
6565
template<> void ft<int>() {}
6666
template void ft<char>(); // expected-error {{undefined}}
6767

68-
template<typename T> int mt<T*>; // expected-warning {{extension}}
69-
template<> int mt<int>; // expected-warning {{extension}}
68+
template<typename T> int mt<T*>;
69+
template<> int mt<int>;
7070
template int mt<int*>;
7171
template int mt<char>; // expected-error {{undefined}}
7272

@@ -92,8 +92,8 @@ namespace inline_namespaces {
9292
template<> void N::gt<int>() {}
9393
template void N::gt<char>(); // expected-error {{undefined}}
9494

95-
template<typename T> int N::nt<T*>; // expected-warning {{extension}}
96-
template<> int N::nt<int>; // expected-warning {{extension}}
95+
template<typename T> int N::nt<T*>;
96+
template<> int N::nt<int>;
9797
template int N::nt<int*>;
9898
template int N::nt<char>; // expected-error {{undefined}}
9999

test/SemaCXX/cxx98-compat.cpp

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -379,38 +379,22 @@ template<typename T> T var = T(10);
379379
// expected-warning@-4 {{variable templates are a C++1y extension}}
380380
#endif
381381

382+
// No diagnostic for specializations of variable templates; we will have
383+
// diagnosed the primary template.
382384
template<typename T> T* var<T*> = new T();
383-
#ifdef CXX1YCOMPAT
384-
// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
385-
#else
386-
// expected-warning@-4 {{variable templates are a C++1y extension}}
387-
#endif
388-
389385
template<> int var<int> = 10;
390-
#ifdef CXX1YCOMPAT
391-
// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
392-
#else
393-
// expected-warning@-4 {{variable templates are a C++1y extension}}
394-
#endif
395-
396386
template int var<int>;
397387
float fvar = var<float>;
398388

399-
class A {
389+
class A {
400390
template<typename T> static T var = T(10);
401391
#ifdef CXX1YCOMPAT
402392
// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
403393
#else
404394
// expected-warning@-4 {{variable templates are a C++1y extension}}
405-
#endif
406-
407-
template<typename T> static T* var<T*> = new T();
408-
#ifdef CXX1YCOMPAT
409-
// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
410-
#else
411-
// expected-warning@-4 {{variable templates are a C++1y extension}}
412395
#endif
413396

397+
template<typename T> static T* var<T*> = new T();
414398
};
415399

416400
struct B { template<typename T> static T v; };
@@ -428,19 +412,7 @@ template<typename T> T B::v = T();
428412
#endif
429413

430414
template<typename T> T* B::v<T*> = new T();
431-
#ifdef CXX1YCOMPAT
432-
// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
433-
#else
434-
// expected-warning@-4 {{variable templates are a C++1y extension}}
435-
#endif
436-
437415
template<> int B::v<int> = 10;
438-
#ifdef CXX1YCOMPAT
439-
// expected-warning@-2 {{variable templates are incompatible with C++ standards before C++1y}}
440-
#else
441-
// expected-warning@-4 {{variable templates are a C++1y extension}}
442-
#endif
443-
444416
template int B::v<int>;
445417
float fsvar = B::v<float>;
446418

0 commit comments

Comments
 (0)