https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120088
Bug ID: 120088
Summary: Use of uninitialized value in constant expression when
copy-constructing a std::expected<void, int> from
another copy-assigned non-erroneous std::expected
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: eddiejnolan at gmail dot com
Target Milestone: ---
Clang and EDG both reject the following when building with libstdc++:
#include <expected>
constexpr bool quux() {
std::expected<void, int> foo1{std::unexpected{0}};
std::expected<void, int> foo2{};
foo1 = foo2;
[[maybe_unused]] std::expected<void, int> foo3{foo1};
return true;
}
static_assert(quux());
Both of them complain about accessing an uninitialized object in a constant
expression, which Clang specifically flags as `_Er _M_unex;`.
Compiler Explorer link: https://godbolt.org/z/4ndvWfMMs