[libcxx-commits] [libcxx] [libc++] P3369R0: constexpr for `uninitialized_default_construct` (PR #200163)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 12 03:24:35 PDT 2026


================
@@ -85,10 +85,117 @@ void test_counted()
     assert(Counted::count == 0);
 }
 
----------------
huixie90 wrote:

I guess it is non trivial to test the behaviour : 
- the fact that it is uninitialised
- it is in constexpr

A wild suggestion of testing this with a verify test:

```
constexpr int test() {
    union {
        int c[2];
    } u;

    std::uninitialized_default_construct(&u.c[0], &u.c[2]);
    return u.c[0];
}

static_assert(test() == 0); // this should trigger an error that reading uninitialised values in constant expression
```


https://github.com/llvm/llvm-project/pull/200163


More information about the libcxx-commits mailing list