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.
data_member_spec should throw on anonymous union typesSection: 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):
—
dealias(type)does not represent an anonymous union type,
Though, maybe better:
—
remove_all_extents(dealias(type))does not represent an anonymous union type,
Proposed resolution:
This wording is relative to N5046.
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::exceptionunless the following conditions are met:
(5.1) —
dealias(type)represents either an object type or a reference type;(5.?) —
remove_all_extents(dealias(type))does not represent an anonymous union type,(5.2) — […]
[…]