Issue 135601
Summary "uninitialized when used here" warning in successful constant _expression_ evaluation
Labels new issue
Assignees
Reporter Fedr
    This program:
```
#include <memory>

struct A {
    int i, j;
    constexpr A() : i((std::construct_at(&j, 2), j-1)) {}
};
constexpr A a{};
static_assert(a.i == 1);
static_assert(a.j == 2);
```
is accepted in GCC and MSVC.

Clang also accepts it with the warning:
```
<source>:5:50: warning: field 'j' is uninitialized when used here [-Wuninitialized]
    5 |     constexpr A() : i((std::construct_at(&j, 2), j-1)) {}
      | ^
```
Online demo: https://gcc.godbolt.org/z/YzEoPPj96

This looks contradicting, since reading of uninitialized values in constant expressions must result in hard fail. Or the program is ok, and the diagnostic is simply wrong.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to