[clang] [Clang] Reject declaring an alias template with the same name as its template parameter. (PR #123533)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 19 21:12:15 PST 2025
================
@@ -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;
+ }
+ }
+
----------------
zyn0217 wrote:
Did you investigate why the if block around line 13428 doesn't work? I would have expected it to catch the issue earlier, before the creation of TypeAliasDecl.
```cpp
// Warn about shadowing the name of a template parameter.
if (Previous.isSingleResult() &&
Previous.getFoundDecl()->isTemplateParameter()) {
DiagnoseTemplateParameterShadow(Name.StartLocation,Previous.getFoundDecl());
Previous.clear();
}
```
https://github.com/llvm/llvm-project/pull/123533
More information about the cfe-commits
mailing list