Skip to content

Commit af464c6

Browse files
authored
[Clang][diagnostics] Fix structured binding shadows template param loc (#129116)
Fix structured binding shadows template parameter location Fixes: #129060
1 parent 6e59282 commit af464c6

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ Improvements to Clang's diagnostics
220220
:doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
221221
feature will be default-enabled with ``-Wthread-safety`` in a future release.
222222

223+
- Improve the diagnostics for shadows template parameter to report correct location (#GH129060).
224+
223225
Improvements to Clang's time-trace
224226
----------------------------------
225227

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,7 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
883883
// It's not permitted to shadow a template parameter name.
884884
if (Previous.isSingleResult() &&
885885
Previous.getFoundDecl()->isTemplateParameter()) {
886-
DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
887-
Previous.getFoundDecl());
886+
DiagnoseTemplateParameterShadow(B.NameLoc, Previous.getFoundDecl());
888887
Previous.clear();
889888
}
890889

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,14 @@ struct A {
162162
};
163163
A<0>::B a;
164164
}
165+
166+
template <typename T> int shadow() { // expected-note{{template parameter is declared here}}
167+
using arr = int[1];
168+
// expected-warning@+1 {{decomposition declarations are a C++17 extension}}
169+
auto [
170+
T // expected-error {{declaration of 'T' shadows template parameter}}
171+
] = arr{};
172+
return 0;
173+
}
174+
175+
auto Use = shadow<int>();

0 commit comments

Comments
 (0)