[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
Sun Apr 19 22:38:34 PDT 2026
================
@@ -402,6 +402,12 @@ struct __optional_destruct_base<_Tp, false> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reset() noexcept {
if (__engaged_) {
__val_.~value_type();
+ // TODO: Remove the workaround when supported compilers have CWG2424 implemented.
+# if _LIBCPP_STD_VER >= 20
+ if consteval {
----------------
frederick-vs-ja wrote:
I think we should just use the extension as it's available in C++20 mode. See https://libcxx.llvm.org/CodingGuidelines.html#use-extensions-if-they-simplify-the-code.
I personally don't want to expose the workaround to C++17 mode or non-constant evaluation. If less code branches is desired, we may switch to use assignment unconditionally.
https://github.com/llvm/llvm-project/pull/192888
More information about the libcxx-commits
mailing list