Title
`data_member_spec` should throw on anonymous union types
Status
new
Section
[meta.reflection.define.aggregate]
Submitter
Jakub Jelinek

Created on 2026-06-04.00:00:00 last changed 1 week ago

Messages

Date: 2026-06-13.13:22:06

Proposed resolution:

This wording is relative to N5046.

  1. Modify [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. […]

Date: 2026-06-04.00:00:00

CWG 3130 added to [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 [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,

History
Date User Action Args
2026-06-13 13:22:06adminsetmessages: + msg16435
2026-06-04 00:00:00admincreate