https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125491
Bug ID: 125491
Summary: GCC accepts a constexpr variable whose user-defined
copy constructor leaves a subobject uninitialized
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: qurong at ios dot ac.cn
Target Milestone: ---
GCC 15.2.0 accepts the following C++20 program, while Clang 22 rejects it:
struct B {
int x;
bool failed;
constexpr B() : failed(false) {}
constexpr B(const B& o) : failed(o.failed) {}
};
constexpr B id(const B& b) {
return b;
}
constexpr B q = id(B());
GCC: gcc15 15.2.0
-std=c++20: accepts
-std=c++20 -pedantic-errors: accepts
Clang: clang++-22 22.0.0
-std=c++20: rejects
-std=c++20 -pedantic-errors: rejects
Clang diagnostic:
error: constexpr variable 'q' must be initialized by a constant expression
note: subobject 'x' is not initialized