False positive `-Wuninitialized` warning in member init list involving `typeid`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Consider this code:
```cpp
#include
struct A
{
int operator()(const std::type_info &);
};
struct B
{
A a;
int b;
template
B(T t)
: b(a(typeid(t)))
{}
};
```
Clang 21 and trunk incorrectly warn: https://gcc.godbolt.org/z/GvhKaavoM
```console
:15:13: warning: field 'a' is uninitialized when used here [-Wuninitialized]
15 | : b(a(typeid(t)))
|
```
This is a false positive, because `a` is initialized before `b` because it's declared first, regardless of the contents of the member init list.
This is also sensitive to how the constructor of `B` is written. Making it a non-template or removing `typeid` seems to remove the warning.
Contributor guide
Assessment
This issue has not been assessed yet.