This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4517. data_member_spec should throw for cv-qualified unnamed bit-fields

Section: 21.4.16 [meta.reflection.define.aggregate] Status: New Submitter: Marek Polacek Opened: 2026-02-05 Last modified: 2026-02-09

Priority: Not Prioritized

View all other issues in [meta.reflection.define.aggregate].

View all issues with New status.

Discussion:

DR 2229 changed 11.4.10 [class.bit] p2 to say:

An unnamed bit-field shall not be declared with a cv-qualified type.

It follows that define_aggregate should have the same limitation, and thus in:

#include <meta>

constexpr auto d1 = std::meta::data_member_spec(^^const int, { .bit_width = 1 });
constexpr auto d2 = std::meta::data_member_spec(^^volatile int, { .bit_width = 1 });
constexpr auto d3 = std::meta::data_member_spec(^^const volatile int, { .bit_width = 1 });

all three data_member_spec should throw.

Proposed resolution:

This wording is relative to N5032.

  1. Modify 21.4.16 [meta.reflection.define.aggregate] as indicated:

    consteval info data_member_spec(info type, data_member_options options);
    

    -4- Returns: […]

    -5- Throws: meta::exception unless the following conditions are met:

    • (5.1) — dealias(type) represents either an object type or a reference type;

    • (5.2) — if options.name contains a value, then: […]

    • (5.3) — if options.name does not contain a value, then options.bit_width contains a value;

    • (5.4) — if options.bit_width contains a value V, then

      • (5.4.1) — is_integral_type(type) || is_enum_type(type) is true,

      • (5.4.2) — options.alignment does not contain a value,

      • (5.4.3) — options.no_unique_address is false,

      • (5.4.4) — V is not negative, and

      • (5.4.5) — if V equals 0, then options.name does not contain a value; and

      • (5.4.?) — if options.name does not contain a value, then is_const(type) || is_volatile(type) is false; and

    • (5.5) — if options.alignment contains a value, it is an alignment value (6.8.3 [basic.align]) not less than alignment_of(type).