| Issue |
176933
|
| Summary |
Clang fails to diagnose of incorrect order of initialization or call to uninitialized member
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
SpiderCh
|
**What code / commands /steps will reproduce the problem?**
Compile the sample code:
```C++
#include <memory>
#include <iostream>
class A
{
int * _val;
public:
A(): _val(new int(4)) {}
~A() { delete _val; }
int get() const noexcept { return *_val; }
};
class B
{
int _val {0};
public:
B(const A& a): _val(a.get()) {}
int get() const noexcept { return _val; }
};
class C
{
B b;
A a {};
public:
C(): b(a) {}
int get() const noexcept { return b.get(); }
};
int main()
{
C c;
std::cout << c.get() << std::endl;
}
```
**Compiler Explorer link:**
https://godbolt.org/z/T6bePEMT4
**What is the expected result?**
The program is ill-formed; the compiler should diagnose the incorrect initialization order.
**What happens instead?**
Compilation is successful. Invalid code is accepted.
GCC in this example emits warning: https://godbolt.org/z/Ts4YTWE6e
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs