Skip to content
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ Bug Fixes to C++ Support
- Fixed a crash caused by the incorrect construction of template arguments for CTAD alias guides when type
constraints are applied. (#GH122134)
- Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033)
- Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423)


Bug Fixes to AST Handling
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13464,6 +13464,14 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, AccessSpecifier AS,
}
TemplateParameterList *TemplateParams = TemplateParamLists[0];

// Check shadowing of a template parameter name
for (NamedDecl *TP : TemplateParams->asArray()) {
if (NameInfo.getName() == TP->getDeclName()) {
DiagnoseTemplateParameterShadow(Name.StartLocation, TP);
return nullptr;
}
}

// Check that we can declare a template here.
if (CheckTemplateDeclScope(S, TemplateParams))
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ namespace PartialSpecialization {

namespace FixedAliasTemplate {
template<typename,typename,typename> struct S {};
template<typename T, typename U> using U = S<T, int, U>; // expected-note 2{{template parameter is declared here}}
template<typename...Ts> U<Ts...> &f(U<Ts...>, Ts...); // expected-error 2{{pack expansion used as argument for non-pack parameter of alias template}}
template<typename T, typename U> using Z = S<T, int, U>; // expected-note 2{{template parameter is declared here}}
template<typename...Ts> Z<Ts...> &f(Z<Ts...>, Ts...); // expected-error 2{{pack expansion used as argument for non-pack parameter of alias template}}
S<int, int, double> &s1 = f({}, 0, 0.0); // expected-error {{no matching function}}
}

Expand Down
5 changes: 3 additions & 2 deletions clang/test/SemaCXX/alias-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ namespace InFunctions {
template<typename...T> struct S3 { // expected-note {{template parameter is declared here}}
template<typename Z> using T = int; // expected-error {{declaration of 'T' shadows template parameter}}
};
template<typename Z> using Z = Z;
template<typename Z> // expected-note {{template parameter is declared here}}
using Z = Z; // expected-error {{declaration of 'Z' shadows template parameter}}
}

namespace ClassNameRedecl {
Expand Down Expand Up @@ -191,4 +192,4 @@ int g = sfinae_me<int>(); // expected-error{{no matching function for call to 's

namespace NullExceptionDecl {
template<int... I> auto get = []() { try { } catch(...) {}; return I; }; // expected-error{{initializer contains unexpanded parameter pack 'I'}}
}
}
Loading