https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106291
Bug ID: 106291 Summary: Literal class can appear in the constant-expression of a declaration of a bit-field Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: xmh970252187 at gmail dot com Target Milestone: --- struct A{ constexpr operator int(){ return 8; } }; struct B{ int a:A{}; }; GCC rejects this example, with a diagnosis that > error: width of bit-field 'a' has non-integral type 'A' [expr.const] p9 explicitly permit this case. > If an expression of literal class type is used in a context where an integral > constant expression is required, then that expression is contextually > implicitly converted ([conv]) to an integral or unscoped enumeration type and > the selected conversion function shall be constexpr. Clang accepts this example