llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.91k stars 11.52k forks source link

Redeclaration of explicitly defaulted comparison operator makes it undefined #105248

Open Fedr opened 3 weeks ago

Fedr commented 3 weeks ago

This program

struct A {
    friend constexpr bool operator ==(const A &, const A &) noexcept = default;
};

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

looks valid and it is accepted by EDG and MSVC. But Clang rejects it with the error

undefined function 'operator==' cannot be used in a constant expression

GCC unfortunately has a similar issue.

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

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

llvmbot commented 3 weeks ago

@llvm/issue-subscribers-clang-frontend

Author: Fedor Chelnokov (Fedr)

This program ``` struct A { friend constexpr bool operator ==(const A &, const A &) noexcept = default; }; constexpr bool operator ==(const A &, const A &) noexcept; static_assert( A{} == A{} ); ``` looks valid and it is accepted by EDG and MSVC. But Clang rejects it with the error > undefined function 'operator==' cannot be used in a constant expression GCC unfortunately has a similar issue. Online demo: https://gcc.godbolt.org/z/azqbosPTd Related discussion: https://stackoverflow.com/q/78889523/7325599