public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99629] New: Misleading diagnostic when looking up rewritten candidate and failing
@ 2021-03-17 16:02 barry.revzin at gmail dot com
  2021-03-17 16:22 ` [Bug c++/99629] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: barry.revzin at gmail dot com @ 2021-03-17 16:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99629
           Summary: Misleading diagnostic when looking up rewritten
                    candidate and failing
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

>From StackOverflow (https://stackoverflow.com/q/66674463/2069064):

#include <compare>

struct S {};

int operator<=>(S, int) { return 0;  }
S   operator<=>(S,   S) { return {}; }

auto x = S{} < S{};

gcc correctly rejects this code as ill-formed. However, the diagnostic provided
is:

<source>:8:14: error: no match for 'operator<' (operand types are 'S' and
'int')
    8 | auto x = S{} < S{};
      |          ~~~~^~~~~

This is technically correct (in the sense that the compiler should be looking
for, specifically, an operator< between S and 0 and fail because it does not
find such a thing) but it's quite a confusing diagnostic since (a) the
highlighted line is not comparing an S to an int and (b) it sure looks like
from the code that you can compare an S to an int. 

It would be nice if the diagnostic somehow made clear that having found
operator<=>(S, S) that it's trying to resolve S{} < S{} as (S{} <=> S{}) < 0
and that subsequent lookup doesn't consider rewritten candidates somehow. 

Not especially high priority (I don't expect this to be an especially common
idiom...), more of a nice to have.

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

* [Bug c++/99629] Misleading diagnostic when looking up rewritten candidate and failing
  2021-03-17 16:02 [Bug c++/99629] New: Misleading diagnostic when looking up rewritten candidate and failing barry.revzin at gmail dot com
@ 2021-03-17 16:22 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-17 16:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-03-17
           Keywords|                            |diagnostic

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

end of thread, other threads:[~2021-03-17 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 16:02 [Bug c++/99629] New: Misleading diagnostic when looking up rewritten candidate and failing barry.revzin at gmail dot com
2021-03-17 16:22 ` [Bug c++/99629] " 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).