[cfe-users] [EXT] Final C++20 rules and -Wambiguous-reversed-operator

Romain GEISSLER via cfe-users cfe-users at lists.llvm.org
Thu Mar 19 05:27:32 PDT 2020



> Le 15 mars 2020 à 20:14, Richard Smith <richard at metafoo.co.uk> a écrit :
> 
> No, we still don't have a resolution from the C++ committee, but it's being discussed by various implementers, and we hope to present to the committee a suggested set of changes to minimize the pain to users as soon as we can. I expect we will change /something/ as a DR fix against C++20, but the exact details are unclear.

Hi,

Thanks for the heads up.

I am not sure how valid is my request, but I found a case where I wished -Wambiguous-reversed-operator would avoid what today with clang 10 is a strong error.

Consider this code: the == comparison warning is avoidable with -Wambiguous-reversed-operator, but not the != comparison. This make existing C++17 code behavior non-symetric when migrating to pack C++20, and a bit awkward for users:

template <typename T> struct A
{
    bool operator==(const T&) const;
    bool operator!=(const T&) const;
};

struct B : public A<B> {};

bool f()
{
    bool a1 = B() == B(); // Works, only a -Wambiguous-reversed-operator warning
    bool a2 = B() != B(); // Strong error, which you can't avoid with -Wno-ambiguous-reversed-operator flag
}

Do you think that in the meantime while we wait for the C++ committee to standardize a real DR clang 10 should be update to also just warns in such cases involving != ?

Cheers,
Romain


More information about the cfe-users mailing list