https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114219
Bug ID: 114219 Summary: [expr.const] lvalue-to-rvalue conversion is not diagnosed to disqualify constant expressions for empty classes Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: janschultke at googlemail dot com Target Milestone: --- https://godbolt.org/z/jhcP8WPn8 Code to reproduce ================= struct S {}; constexpr int f(S s) { constexpr S _ = s; return 0; } S s; constexpr int _ = f(s); Issue description ================= This code compiles, but should produce errors for both constexpr initializations. According to [expr.const] p5.9, the initializers of _ cannot be constant expression because they contain lvalue-to-rvalue conversion of s, whose lifetime did not begin within the evaluation of the constant expression, and which is not usable in constant expressions. It shouldn't matter whether S is an empty class or has members; the lvalue-to-rvalue conversion in itself disqualifies expressions from being constant expressions.