[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
Thu Feb 15 09:17:03 PST 2024


================
@@ -885,16 +885,19 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation,
 /// that the template parameter 'PrevDecl' is being shadowed by a new
 /// declaration at location Loc. Returns true to indicate that this is
 /// an error, and false otherwise.
-void Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl) {
+void Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl,
+                                           bool IssueWarning) {
----------------
sdkrystian wrote:

@AaronBallman In VS20222 the javadocs show up even when they are attached to the definition... but I'll move them to the declaration to be on the safe side :)

While I agree with changing the name to `SupportedAsExtension`, I don't think the change to the diagnostic selection logic is quite right. When MSVC compatibility **is** enabled, template parameter shadowing is _always_ allowed (read: there are no cases where shadowing would be an error with MSVC compatibility enabled), so we should issue the MSVC specific diagnostic regardless of `SupportedAsExtension`.  `SupportedAsExtension` should be used to select between the error/extension diagnostic only when MSVC compatibility **is not** enabled. Perhaps we name it `SupportedForCompatibility` instead? 



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


More information about the cfe-commits mailing list