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.