Issue 160657
Summary False positive `-Wuninitialized` warning in member init list involving `typeid`
Labels new issue
Assignees
Reporter HolyBlackCat
    Consider this code:
```cpp
#include <typeinfo>

struct A
{
    int operator()(const std::type_info &);
};

struct B
{
    A a;
    int b;

    template <typename T>
 B(T t)
        : b(a(typeid(t)))
    {}
};
```
Clang 21 and trunk incorrectly warn: https://gcc.godbolt.org/z/GvhKaavoM
```console
<source>: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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to