Skip to content

trunk regression: operator== is not defined #104720

Open
@Fedr

Description

@Fedr

This C++20 program

#include <compare>

struct A {
    friend constexpr auto operator<=>(const A &, const A &) = default;
};

constexpr bool operator ==(const A &, const A &) noexcept;

static_assert( ((bool(*)(const A &, const A &))&operator==)( A{}, A{} ) );

is accepted in GCC and Clang 18.1, but the current Clang trunk rejects it with the error

<source>:9:16: error: static assertion expression is not an integral constant expression
    9 | static_assert( ((bool(*)(const A &, const A &))&operator==)( A{}, A{} ) );
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:9:16: note: undefined function 'operator==' cannot be used in a constant expression
<source>:4:27: note: declared here
    4 |     friend constexpr auto operator<=>(const A &, const A &) = default;
      |                           ^

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyregression:19Regression in 19 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions