Skip to content

Commit 2a09523

Browse files
authored
[clang] Add diagnostic for unresolved using declaration that shadows template parameters (#131328)
Fix #129411
1 parent 19b25a4 commit 2a09523

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ Bug Fixes to C++ Support
310310
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
311311
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)
312312
- Clang now properly instantiates destructors for initialized members within non-delegating constructors. (#GH93251)
313+
- Correctly diagnoses if unresolved using declarations shadows template paramters (#GH129411)
313314

314315
Bug Fixes to AST Handling
315316
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12895,6 +12895,10 @@ NamedDecl *Sema::BuildUsingDeclaration(
1289512895
SS, NameInfo, IdentLoc))
1289612896
return nullptr;
1289712897

12898+
if (Previous.isSingleResult() &&
12899+
Previous.getFoundDecl()->isTemplateParameter())
12900+
DiagnoseTemplateParameterShadow(IdentLoc, Previous.getFoundDecl());
12901+
1289812902
if (HasTypenameKeyword) {
1289912903
// FIXME: not all declaration name kinds are legal here
1290012904
D = UnresolvedUsingTypenameDecl::Create(Context, CurContext,

clang/test/Parser/cxx-template-decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ template<template<typename> class T> struct shadow8 { // expected-note{{template
109109
template<template<typename> class T> struct inner; // expected-error{{declaration of 'T' shadows template parameter}}
110110
};
111111

112+
template<class>
113+
class shadow9_;
114+
115+
template<class T> // expected-note{{template parameter is declared here}}
116+
class shadow9 : public shadow9_<T> {
117+
using typename shadow9_<T>::T; // expected-error{{declaration of 'T' shadows template parameter}}
118+
};
119+
112120
// Non-type template parameters in scope
113121
template<int Size>
114122
void f(int& i) {

0 commit comments

Comments
 (0)