https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125338

            Bug ID: 125338
           Summary: the integral constant expression in a bit-field width
                    may involve a constexpr conversion
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aoliva at gcc dot gnu.org
  Target Milestone: ---

// { dg-do compile }
struct S {
  constexpr operator int () const { return 4; }
};
constexpr S s;
struct T {
  unsigned i : s;
};

but we get error: width of bit-field ‘i’ has non-integral type ‘const S’

bit-field widths require integral constant expression, but there are provisions
for constexpr conversion of class types to integral types in C++11's
[expr.const]/5, later reformulated into contextual conversions.

The use of such integral constant expressions of literal class type that
involve constexpr conversion works in other contexts, such as enum
initializers, regardless of the fixedness of the underlying type.  The
too-strict requirement appears to be specific to bit-field widths.

Reply via email to