Diagnose template alias declarations in local classes.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 6 Apr 2016 17:38:58 +0000 (17:38 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 6 Apr 2016 17:38:58 +0000 (17:38 +0000)
Patch by Erik Pilkington!

llvm-svn: 265571

clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p2.cpp

index e7c3b6a..995378c 100644 (file)
@@ -8585,6 +8585,10 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S,
     }
     TemplateParameterList *TemplateParams = TemplateParamLists[0];
 
+    // Check that we can declare a template here.
+    if (CheckTemplateDeclScope(S, TemplateParams))
+      return nullptr;
+
     // Only consider previous declarations in the same scope.
     FilterLookupForScope(Previous, CurContext, S, /*ConsiderLinkage*/false,
                          /*ExplicitInstantiationOrSpecialization*/false);
index c24d5a9..feeb362 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
 
 template <typename>
 void quux();
@@ -8,5 +8,7 @@ void fun() {
     template <typename> struct bar {};  // expected-error{{templates cannot be declared inside of a local class}}
     template <typename> void baz() {}   // expected-error{{templates cannot be declared inside of a local class}}
     template <typename> void qux();     // expected-error{{templates cannot be declared inside of a local class}}
+    template <typename> using corge = int; // expected-error{{templates cannot be declared inside of a local class}}
+    template <typename T> static T grault; // expected-error{{static data member}} expected-error{{templates cannot be declared inside of a local class}}
   };
 }