[clang] Reapply "[Clang][Sema] Diagnose function/variable templates that shadow their own template parameters (#78274)" (PR #79683)

Krystian Stasiowski via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 27 01:18:18 PST 2024


================
@@ -6506,12 +6500,25 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
     RemoveUsingDecls(Previous);
   }
 
-  if (Previous.isSingleResult() &&
-      Previous.getFoundDecl()->isTemplateParameter()) {
+  // if (Previous.isSingleResult() &&
+  //    Previous.getFoundDecl()->isTemplateParameter()) {
+  if (auto *TPD = Previous.getAsSingle<NamedDecl>(); TPD && TPD->isTemplateParameter()) {
+    // Older versions of clang allowed the names of function/variable templates
+    // to shadow the names of their template parameters. For the compatibility purposes
+    // we detect such cases and issue a default-to-error warning that can be disabled with
+    // -fno-strict-primary-template-shadow.
----------------
sdkrystian wrote:

Yes :)

https://github.com/llvm/llvm-project/pull/79683


More information about the cfe-commits mailing list