https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93699
Bug ID: 93699 Summary: [gcc10] Invalid operator== (returning non-bool type) candidate Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: laurent.stacul at gmail dot com Target Milestone: --- Hello, With a HEAD of gcc: gcc -v [jobs: 2][history: 5226] Reading specs from /remote/tools/Linux/2.6/1A/toolchain/x86_64-v20.0.8/bin/../lib/gcc/x86_64-1a-linux-gnu/10.0.1/specs COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/remote/tools/Linux/2.6/1A/toolchain/x86_64-v20.0.8/bin/../libexec/gcc/x86_64-1a-linux-gnu/10.0.1/lto-wrapper Target: x86_64-1a-linux-gnu Configured with: /workdir/src/gcc-10.0.1/configure --build=x86_64-1a-linux-gnu --host=x86_64-1a-linux-gnu --target=x86_64-1a-linux-gnu --prefix=/opt/1A/toolchain/x86_64-v20.0.8 --with-local-prefix=/opt/1A/toolchain/x86_64-v20.0.8 --with-native-system-header-dir=/opt/1A/toolchain/x86_64-v20.0.8/include --enable-languages=c,c++,fortran --disable-multilib --enable-linker-build-id --with-linker-hash-style=gnu --enable-gnu-indirect-function --with-build-config=bootstrap-lto --enable-install-libiberty --enable-checking=release Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.0.1 20200211 (experimental) (GCC) In the following example, I think there is something odd: class Base { public: virtual int operator==(const Base&) const { return 1; } }; class Derived : public Base { public: virtual int operator==(const Base&) const { return 1; } }; int main(int argc, const char *argv[]) { Base* b; Derived* d; if (*b == *d) { return 1; } return 0; } The compilation is done as follows: $ g++ -std=gnu++2a rep.cpp <source>: In function 'int main(int, const char**)': <source>:19:12: error: return type of 'virtual int Derived::operator==(const Base&) const' is not 'bool' 19 | if (*b == *d) { | ~~~^~~~~ <source>:19:12: note: used as rewritten candidate for comparison of 'Base' and 'Derived' Compiler returned: 1 I understand that C++20 introduced the possibility for the compiler to have the reversed primary operator to be candidate in the function resolution, but as far as I understand the primary comparison operators are not rewritten. Is there a bug in the C++20 support or did I miss something ? Regards, Stac