public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102846] New: Misleading suggestion to include cassert
@ 2021-10-19 19:56 federico.kircheis at gmail dot com
  2021-10-19 22:04 ` [Bug c++/102846] " redi at gcc dot gnu.org
  2021-10-24  6:18 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: federico.kircheis at gmail dot com @ 2021-10-19 19:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102846
           Summary: Misleading suggestion to include cassert
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.kircheis at gmail dot com
  Target Milestone: ---

Consider following snippet (https://godbolt.org/z/9e19bP1Gh)


----
#include <cassert>

template <class F, class C1>
auto verify(F f, C1* p1){
    f(p1);
    return p1;
}

void bar(void* ptr){
    // no error here, as cassert is included
    assert(true); 

    // error here, gcc thinks that cassert is missing
    auto v = verify(assert, ptr); 

}
----

GCC does not compile the program successfully (this is unfortunately correct),
but the diagnostic is misleading:

----
<source>: In function 'void bar(void*)':
<source>:15:21: error: 'assert' was not declared in this scope
   15 |     auto v = verify(assert, ptr);
      |                     ^~~~~~
<source>:2:1: note: 'assert' is defined in header '<cassert>'; did you forget
to '#include <cassert>'?
    1 | #include <cassert>
  +++ |+#include <cassert>
    2 | 
----

As assert is a macro and not a function, it cannot be generally used as an
argument of another function.
Thus the error is not the not-missing include.

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

* [Bug c++/102846] Misleading suggestion to include cassert
  2021-10-19 19:56 [Bug c++/102846] New: Misleading suggestion to include cassert federico.kircheis at gmail dot com
@ 2021-10-19 22:04 ` redi at gcc dot gnu.org
  2021-10-24  6:18 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-19 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The "did you forget to include" diagnostics don't look at the context, they
just do simple string matching of undeclared identifiers against a hardcoded
list of standard names, and suggest a header.

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

* [Bug c++/102846] Misleading suggestion to include cassert
  2021-10-19 19:56 [Bug c++/102846] New: Misleading suggestion to include cassert federico.kircheis at gmail dot com
  2021-10-19 22:04 ` [Bug c++/102846] " redi at gcc dot gnu.org
@ 2021-10-24  6:18 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-24  6:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-10-24

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed,
Clang message is even funnier:
<source>:15:21: error: use of undeclared identifier 'assert'; did you mean
'__assert'?

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 19:56 [Bug c++/102846] New: Misleading suggestion to include cassert federico.kircheis at gmail dot com
2021-10-19 22:04 ` [Bug c++/102846] " redi at gcc dot gnu.org
2021-10-24  6:18 ` pinskia 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).