<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114069>114069</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Class fields with placeholder names cause incorrect instantiation of in-class initializers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
groundswellaudio
</td>
</tr>
</table>
<pre>
MRE :
https://godbolt.org/z/Mjdnz8G31
```cpp
#include <cassert>
template <class T>
struct A {
T _ = 5;
T _ = 4;
};
int main() {
A<int> a;
auto [x, y] = a;
assert( y == 4 );
}
```
`assert( y == 4 )` fails because Clang finds the in-class init pattern like this (in Sema::BuildCXXDefaultInitExpr) :
```cpp
CXXRecordDecl *ClassPattern = ParentRD->getTemplateInstantiationPattern();
DeclContext::lookup_result Lookup = ClassPattern->lookup(Field->getDeclName());
FieldDecl *Pattern = nullptr;
for (auto *L : Lookup) {
if ((Pattern = dyn_cast<FieldDecl>(L)))
break;
}
```
Obviously this cannot works with `_`. I think to remedy this imply keeping track of the pattern of an instantiated field with a placeholder name in some auxiliary structure? The entry would only need to be temporary until its consumed by Sema::BuildCXXDefaultInitExpr.
Also I think a warning should be emitted that we're using a C++26 feature before its time?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU1v4zYQ_TX0ZRBDoixbPujgj7hYINsutjnkFlDiyOKaIgVyuI7z6wtKWsdOW7RAwNj0zLx5855Gwnt1NIgly7cs389EoNa68uhsMNKfUWsRpLKzyspL-fX7I7BsAyzZs2Qzni1R71m2YfzA-OFoZWU1za07Mn54Z_zw9Yc078VvWXqbxJbJ-Ff3_XTDM2VqHSQCy3a18B4dsezxNouw67WgMUIL7-H5GuHJhZpgA2y1HW8AAJ7hFVi2h5xl_3C7uN6y1f7j83AqQ9AJZRgvGF_fV92wbKdM7A7EXWERyALLt2-M7-DC8v0AcxMz0eIFXOJ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