llvm / llvm/llvm-project

False positive `-Wuninitialized` warning in member init list involving `typeid`

Open
#160,657 0 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics false-positive
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.