Skip to content

Commit 8658d15

Browse files
committed
Revert "[Clang][Sema] Diagnose function/variable templates that shadow their own template parameters (#78274)"
This reverts commit fc02532. This errors is disruptive to downstream projects and should be reintroduced as a separate on-by-default warning. #78274
1 parent 21199f9 commit 8658d15

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ Improvements to Clang's diagnostics
590590
- Clang now diagnoses the requirement that non-template friend declarations with requires clauses
591591
and template friend declarations with a constraint that depends on a template parameter from an
592592
enclosing template must be a definition.
593-
- Clang now diagnoses function/variable templates that shadow their own template parameters, e.g. ``template<class T> void T();``.
594593
- Clang now diagnoses incorrect usage of ``const`` and ``pure`` attributes, so ``-Wignored-attributes`` diagnoses more cases.
595594
- Clang now emits more descriptive diagnostics for 'unusual' expressions (e.g. incomplete index
596595
expressions on matrix types or builtin functions without an argument list) as placement-args

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6377,6 +6377,12 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
63776377
} else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
63786378
return nullptr;
63796379

6380+
// The scope passed in may not be a decl scope. Zip up the scope tree until
6381+
// we find one that is.
6382+
while ((S->getFlags() & Scope::DeclScope) == 0 ||
6383+
(S->getFlags() & Scope::TemplateParamScope) != 0)
6384+
S = S->getParent();
6385+
63806386
DeclContext *DC = CurContext;
63816387
if (D.getCXXScopeSpec().isInvalid())
63826388
D.setInvalidType();
@@ -6529,12 +6535,6 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
65296535
if (getLangOpts().CPlusPlus)
65306536
CheckExtraCXXDefaultArguments(D);
65316537

6532-
// The scope passed in may not be a decl scope. Zip up the scope tree until
6533-
// we find one that is.
6534-
while ((S->getFlags() & Scope::DeclScope) == 0 ||
6535-
(S->getFlags() & Scope::TemplateParamScope) != 0)
6536-
S = S->getParent();
6537-
65386538
NamedDecl *New;
65396539

65406540
bool AddToScope = true;

clang/test/CXX/temp/temp.res/temp.local/p6.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,16 @@ template<int T> struct Z { // expected-note 16{{declared here}}
127127
template<typename T> // expected-note {{declared here}}
128128
void f(int T) {} // expected-error {{declaration of 'T' shadows template parameter}}
129129

130+
// FIXME: These are ill-formed: a template-parameter shall not have the same name as the template name.
130131
namespace A {
131132
template<typename T> struct T {}; // expected-error{{declaration of 'T' shadows template parameter}}
132133
// expected-note@-1{{template parameter is declared here}}
133-
template<typename T> struct U {
134-
template<typename V> struct V {}; // expected-error{{declaration of 'V' shadows template parameter}}
135-
// expected-note@-1{{template parameter is declared here}}
136-
};
137134
}
138135
namespace B {
139-
template<typename T> void T() {} // expected-error{{declaration of 'T' shadows template parameter}}
140-
// expected-note@-1{{template parameter is declared here}}
141-
142-
template<typename T> struct U {
143-
template<typename V> void V(); // expected-error{{declaration of 'V' shadows template parameter}}
144-
// expected-note@-1{{template parameter is declared here}}
145-
};
136+
template<typename T> void T() {}
146137
}
147138
namespace C {
148-
template<typename T> int T; // expected-error{{declaration of 'T' shadows template parameter}}
149-
// expected-note@-1{{template parameter is declared here}}
150-
template<typename T> struct U {
151-
template<typename V> static int V; // expected-error{{declaration of 'V' shadows template parameter}}
152-
// expected-note@-1{{template parameter is declared here}}
153-
};
139+
template<typename T> int T;
154140
}
155141

156142
namespace PR28023 {

0 commit comments

Comments
 (0)