Skip to content

Default equality operator for an empty union cannot be used in constant expressions #164068

@Fedr

Description

@Fedr

This program

union U {
    constexpr bool operator ==(const U&) const = default;
};

static_assert( U{} == U{} );

is accepted in GCC and EDG. But Clang fails with the error:

<source>:5:16: error: static assertion expression is not an integral constant expression
    5 | static_assert( U{} == U{} );
      |                ^~~~~~~~~~
<source>:5:16: note: pointer to temporary is not a constant expression
<source>:5:16: note: temporary created here

Online demo: https://gcc.godbolt.org/z/MMrbaaWae

Related discussion: https://stackoverflow.com/q/79793373/7325599

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationdiverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:gccDoes the clang frontend diverge from gcc on this issueduplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions