[libcxx-commits] [libcxx] [libc++] Allow a disengaged `optional` to be `constexpr` since C++20 (PR #192888)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 23 05:22:09 PDT 2026


frederick-vs-ja wrote:

> IIUC CWG2424 is about this example: https://godbolt.org/z/KoK9P5aYG
> As you can see, it's still not backported to C++17 or earlier modes, but has been available in C++20 mode since Clang 10, i.e. for 6 or 7 years at this point.

Hmm... in this example `TrivialUnion{}` value-initializes the union and activates its first member (`val`), so IIUC this doesn't fall into the case of CWG2424.

I still think that Clang hasn't completely implemented CWG2424. Without CWG2424, the implementation can infer that a union constituent value of a constexpr object must have exactly one active member. Now Clang is still requiring that a constexpr object to have an active member in some cases, despite allowing a union constructor not to initialize any member.

When there's originally no active member and the union is untouched, Clang allows such a union to be constexpr. However, if the previously active member is destroyed and no member is activated later, currently Clang doesn't permit the union to be constexpr.

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


More information about the libcxx-commits mailing list