diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index e7c3b6af0277..995378c073b4 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -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); diff --git a/clang/test/CXX/temp/temp.decls/temp.mem/p2.cpp b/clang/test/CXX/temp/temp.decls/temp.mem/p2.cpp index c24d5a9b50de..feeb362e34b4 100644 --- a/clang/test/CXX/temp/temp.decls/temp.mem/p2.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.mem/p2.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s template void quux(); @@ -8,5 +8,7 @@ void fun() { template struct bar {}; // expected-error{{templates cannot be declared inside of a local class}} template void baz() {} // expected-error{{templates cannot be declared inside of a local class}} template void qux(); // expected-error{{templates cannot be declared inside of a local class}} + template using corge = int; // expected-error{{templates cannot be declared inside of a local class}} + template static T grault; // expected-error{{static data member}} expected-error{{templates cannot be declared inside of a local class}} }; }