Skip to content

Commit 501b301

Browse files
author
git apple-llvm automerger
committed
Merge commit '8658d1576548' from llvm.org/main into next
2 parents 8117009 + 8658d15 commit 501b301

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
@@ -6380,6 +6380,12 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
63806380
} else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
63816381
return nullptr;
63826382

6383+
// The scope passed in may not be a decl scope. Zip up the scope tree until
6384+
// we find one that is.
6385+
while ((S->getFlags() & Scope::DeclScope) == 0 ||
6386+
(S->getFlags() & Scope::TemplateParamScope) != 0)
6387+
S = S->getParent();
6388+
63836389
DeclContext *DC = CurContext;
63846390
if (D.getCXXScopeSpec().isInvalid())
63856391
D.setInvalidType();
@@ -6532,12 +6538,6 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
65326538
if (getLangOpts().CPlusPlus)
65336539
CheckExtraCXXDefaultArguments(D);
65346540

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

65436543
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)