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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 12 03:58:42 PDT 2026


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

It's a bit unfortunate that the current message is ([Godbolt link](https://godbolt.org/z/4GbT7s8s7)) the following:
```
note: construction of subobject of member 'c' of union with no active member is not allowed in a constant expression
```

How about removing the union layer? ([Godbolt link](https://godbolt.org/z/vPb8ch1W7))
```C++
constexpr int test() {
  int c[2];
  std::uninitialized_default_construct(&c[0], &c[2]);
  return c[0]; // expected-note {{read of uninitialized object is not allowed in a constant expression}}
}

static_assert(test() == 0); // expected-error {{static assertion expression is not an integral constant expression}}
```

BTW, this PR is already using SFINAE-based tricks to verify that these algorithms do start lifetime of elements and leave them with indeterminate values. If the lifetime didn't start, assignment would fail (so that `test_indeterminate_values_result<assign_elements::yes>` would be `false`). If elements had determined values, `test_indeterminate_values_result<assign_elements::no>` would be `true`.
This is really tricky. I'll add `.verify.cpp` tests.

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


More information about the libcxx-commits mailing list