<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/86517>86517</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
-Wclang-diagnostic-shadow-field doesn't work correctly with templates, inheritance, and parameters in non-defining declarations
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
higher-performance
</td>
</tr>
</table>
<pre>
The code
```
template<class T>
struct Base { int index; };
template<class T>
struct Derived : Base<T> { Derived(int index); };
template<class T>
Derived<T>::Derived(int x) { (void)x; }
template struct Derived<int>;
struct Base2 { int index; };
struct Derived2 : Base2 { Derived2(int index); };
Derived2::Derived2(int x) { (void)x; }
```
[demonstrates incorrect diagnostics from Clang](https://godbolt.org/z/j869cn3je):
```
<source>:4:40: warning: parameter 'index' shadows member inherited from type 'Base<int>' [-Wshadow-field]
4 | struct Derived : Base<T> { Derived(int index); };
| ^
<source>:7:17: note: in instantiation of member function 'Derived<int>::Derived' requested here
7 | template struct Derived<int>;
| ^
<source>:2:19: note: declared here
2 | struct Base { int index; };
| ^
```
Specifically, there are 3 issues (which may be related):
1. The behavior is inconsistent between non-templates and templates: there seems to be reason why the diagnostic should appear for `Derived` but be absent for `Derived2`.
1. The diagnostic triggers non-defining declarations unnecessarily: shadowing here is benign here; renaming wouldn't really prevent any problem.
1. The diagnostic fails to trigger on non-declaring definitions: if you rename `Base::index` to `Base::x`, the warning fails to trigger, despite `Derived<T>::Derived(int x)` shadowing it in the implementation.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVtuSozYQ_Rr5pcsuLHGxH3iwPesfyFbtsxANaCMkIolxnK9PNeCxvbM7O6kK5Qsg0X369DkSMgTdWsSSZUeWvazkGDvny063Hfr1gL5xvpdW4apy9bX82iEoVyNLXlhyYHmyfKbLiP1gZEQmTsrIEOArE1_moRD9qCIcZUBgxRG0jaB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