Skip to content

[class.union.anon] Are lambda expressions disallowed in anonymous unions? #706

Open
@hubert-reinterpretcast

Description

@hubert-reinterpretcast

Full name of submitter (unless configured in github; will be published with the issue): Hubert Tong

Reference (section label): class.union.anon

Link to reflector thread (if any): N/A

Issue description:
https://eel.is/c++draft/class.union.anon#1.sentence-3 says:

Nested types, anonymous unions, and functions shall not be declared within an anonymous union.

A lambda expression declares a closure type (https://eel.is/c++draft/expr.prim.lambda#closure-2).

Does that mean that lambda expressions are disallowed in anonymous unions?

Only EDG generates a diagnostic for https://godbolt.org/z/xf96EbKTn:

static union {
  int x = [] { return 42; }();
};

Suggested resolution:

Nested types, including closure types and anonymous unions, and functions shall not be declared within an anonymous union.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions