public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/93699] [gcc10] Invalid operator== (returning non-bool type) candidate
       [not found] <bug-93699-4@http.gcc.gnu.org/bugzilla/>
@ 2020-03-11 10:30 ` laurent.stacul at gmail dot com
  2020-03-11 11:20 ` [Bug c++/93699] " redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: laurent.stacul at gmail dot com @ 2020-03-11 10:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93699

--- Comment #1 from Laurent Stacul <laurent.stacul at gmail dot com> ---
Please note that reversing b and d works fine:

    if (*b == *d) { // This does not work
    if (*d == *b) { // This is ok

Regards,
Stac

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/93699] Invalid operator== (returning non-bool type) candidate
       [not found] <bug-93699-4@http.gcc.gnu.org/bugzilla/>
  2020-03-11 10:30 ` [Bug c++/93699] [gcc10] Invalid operator== (returning non-bool type) candidate laurent.stacul at gmail dot com
@ 2020-03-11 11:20 ` redi at gcc dot gnu.org
  2020-03-11 11:24 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-11 11:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93699

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[gcc10] Invalid operator==  |Invalid operator==
                   |(returning non-bool type)   |(returning non-bool type)
                   |candidate                   |candidate

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started to be rejected with r277865 which implements operator<=>, and I think
the compiler is correct to reject it.

For (*b == *d) the arguments do not match Base::operator==(const Base&)
exactly, so the compiler tries a synthesized operator with reversed arguments,
which is ill-formed because of the bad return type.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/93699] Invalid operator== (returning non-bool type) candidate
       [not found] <bug-93699-4@http.gcc.gnu.org/bugzilla/>
  2020-03-11 10:30 ` [Bug c++/93699] [gcc10] Invalid operator== (returning non-bool type) candidate laurent.stacul at gmail dot com
  2020-03-11 11:20 ` [Bug c++/93699] " redi at gcc dot gnu.org
@ 2020-03-11 11:24 ` redi at gcc dot gnu.org
  2020-03-11 13:28 ` laurent.stacul at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-11 11:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93699

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
P.S. it helps to provide a testcase that doesn't have lots of spurious warnings
when compiled with -Wall -Wextra, because one of the first things I'm going to
do when triaging bug reports is compile with those warnings on.

Uninitialized variables and unused parameters that are not relevant to the bug
are just noise.

Reduced testcase:

struct Base {
    virtual int operator==(const Base&) const {
        return 1;
    }
};

struct Derived : public Base {
    virtual int operator==(const Base&) const {
        return 1;
    }
};

int main()
{
    Base* b = nullptr;
    Derived* d = nullptr;
    if (*b == *d) {
        return 1;
    }
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/93699] Invalid operator== (returning non-bool type) candidate
       [not found] <bug-93699-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-03-11 11:24 ` redi at gcc dot gnu.org
@ 2020-03-11 13:28 ` laurent.stacul at gmail dot com
  2021-12-17  5:12 ` pinskia at gcc dot gnu.org
  2021-12-17 10:18 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: laurent.stacul at gmail dot com @ 2020-03-11 13:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93699

--- Comment #4 from Laurent Stacul <laurent.stacul at gmail dot com> ---
Sorry for this, I will follow your recommendations next time.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/93699] Invalid operator== (returning non-bool type) candidate
       [not found] <bug-93699-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-03-11 13:28 ` laurent.stacul at gmail dot com
@ 2021-12-17  5:12 ` pinskia at gcc dot gnu.org
  2021-12-17 10:18 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17  5:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93699

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang does this as a pedwarn:
<source>:20:12: warning: ISO C++20 requires return type of selected
'operator==' function for rewritten '==' comparison to be 'bool', not 'int'
[-Wrewrite-not-bool]
    if (*b == *d) {
        ~~ ^  ~~


I don't know if it makes sense now to change GCC to do a pedwarn instead of an
error.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/93699] Invalid operator== (returning non-bool type) candidate
       [not found] <bug-93699-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2021-12-17  5:12 ` pinskia at gcc dot gnu.org
@ 2021-12-17 10:18 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-17 10:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93699

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Personally, I think it should remain ill-formed.

Maybe -fpermissive could allow it (for compat with previous standards) but
unfortunately that flag is far too permissive and enables all kinds of ancient
legacy junk. If we cleaned it up to be a bit permissive, not ridiculously
permissive of pre-1998 code, it could be useful here.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-17 10:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-93699-4@http.gcc.gnu.org/bugzilla/>
2020-03-11 10:30 ` [Bug c++/93699] [gcc10] Invalid operator== (returning non-bool type) candidate laurent.stacul at gmail dot com
2020-03-11 11:20 ` [Bug c++/93699] " redi at gcc dot gnu.org
2020-03-11 11:24 ` redi at gcc dot gnu.org
2020-03-11 13:28 ` laurent.stacul at gmail dot com
2021-12-17  5:12 ` pinskia at gcc dot gnu.org
2021-12-17 10:18 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).