[clang] Reapply "[Clang][Sema] Diagnose function/variable templates that shadow their own template parameters (#78274)" (PR #79683)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 27 01:13:45 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff faef68bca852d08511ea0311d8a0d221cb202e73 abc8f062add9e41ce00b9d035c796256a62859ef -- clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaTemplate.cpp clang/test/CXX/temp/temp.res/temp.local/p6.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5c148db481..d0fb4f0991 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8256,7 +8256,8 @@ public:
TemplateSpecializationKind TSK,
bool Complain = true);
- void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl, bool IssueWarning = false);
+ void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl,
+ bool IssueWarning = false);
TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
NamedDecl *ActOnTypeParameter(Scope *S, bool Typename,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index de65b3c09c..2cb971b052 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6502,22 +6502,23 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
// if (Previous.isSingleResult() &&
// Previous.getFoundDecl()->isTemplateParameter()) {
- if (auto *TPD = Previous.getAsSingle<NamedDecl>(); TPD && TPD->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.
+ // 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.
bool IssueShadowingWarning = false;
for (Scope *Inner = S; (Inner->getFlags() & Scope::DeclScope) == 0 ||
- Inner->isTemplateParamScope(); Inner = Inner->getParent()) {
+ Inner->isTemplateParamScope();
+ Inner = Inner->getParent()) {
if (IssueShadowingWarning = Inner->isDeclScope(TPD))
break;
}
// Maybe we will complain about the shadowed template parameter.
if (!D.isInvalidType())
- DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
- TPD,
+ DiagnoseTemplateParameterShadow(D.getIdentifierLoc(), TPD,
IssueShadowingWarning);
// Just pretend that we didn't see the previous declaration.
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 4ba8dfc19d..2993da99ff 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -885,7 +885,8 @@ 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, bool IssueWarning) {
+void Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl,
+ bool IssueWarning) {
assert(PrevDecl->isTemplateParameter() && "Not a template parameter");
// C++ [temp.local]p4:
@@ -894,10 +895,9 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl, b
//
// Make this a warning when MSVC compatibility is requested.
unsigned DiagId = getLangOpts().MSVCCompat
- ? diag::ext_template_param_shadow
- : (IssueWarning
- ? diag::ext_compat_template_param_shadow
- : diag::err_template_param_shadow);
+ ? diag::ext_template_param_shadow
+ : (IssueWarning ? diag::ext_compat_template_param_shadow
+ : diag::err_template_param_shadow);
const auto *ND = cast<NamedDecl>(PrevDecl);
Diag(Loc, DiagId) << ND->getDeclName();
NoteTemplateParameterLocation(*ND);
``````````
</details>
https://github.com/llvm/llvm-project/pull/79683
More information about the cfe-commits
mailing list