Issue 114069
Summary [clang] Class fields with placeholder names cause incorrect instantiation of in-class initializers
Labels clang
Assignees
Reporter groundswellaudio
    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? 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to