Skip to content

default equality operator== const selects not-const conversion operator #102588

@Fedr

Description

@Fedr

This program

struct A {
    int i = 0;
    constexpr operator int() const { return i; }
    constexpr operator int&() { return ++i; }
};

struct B : A {
    bool operator==(const B &) const = default;
};

constexpr bool f() {
    B x;
    return x == x;
}

static_assert( f() ); // fails in Clang

is accepted by GCC and MSVC, but fails static assertion in Clang. Online demo: https://gcc.godbolt.org/z/5hYob3K66

Clang looks wrong here, because not-const operator int& should not be called from within B::operator==(const B &) const.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions