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.

4594. data_member_spec should throw on anonymous union types

Section: 21.4.17 [meta.reflection.define.aggregate] Status: New Submitter: Jakub Jelinek Opened: 2026-06-04 Last modified: 2026-06-13

Priority: Not Prioritized

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

View all issues with New status.

Discussion:

CWG 3130 added to 11.5.2 [class.union.anon]:

"Each object of such an unnamed type shall be such an unnamed object."

restriction. I think we should therefore throw from data_member_spec if one attempts to use it with an anonymous union type.

#include <meta>

struct S { union { int a; long b; };
constexpr auto ctx = std::meta::access_context::unchecked ();
using U = [: members_of (^^S, ctx)[0] :];
constexpr auto m = data_member_spec (^^U, { .name = "_" });

So, add after 21.4.17 [meta.reflection.define.aggregate] bullet (5.2):

  1. dealias(type) does not represent an anonymous union type,

Though, maybe better:

  1. remove_all_extents(dealias(type)) does not represent an anonymous union type,

Proposed resolution:

This wording is relative to N5046.

  1. Modify 21.4.17 [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:

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

    2. (5.?) — remove_all_extents(dealias(type)) does not represent an anonymous union type,

    3. (5.2) — […]

    4. […]