https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120918
Bug ID: 120918 Summary: -Wreturn-type warning is confused by macro Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #define assert(...) ((__VA_ARGS__) ? (void)(1?1:bool(__VA_ARGS__)) : (void)__builtin_abort()) int f() { assert( []{return 1;}() ); } GCC says: a.cc: In function 'int f()': a.cc:5:11: warning: control reaches end of non-void function [-Wreturn-type] 5 | assert( []{return 1;}() ); | ^~~~~~~~~~~~~ a.cc:1:23: note: in definition of macro 'assert' 1 | #define assert(...) ((__VA_ARGS__) ? (void)(1?1:bool(__VA_ARGS__)) : (void)__builtin_abort()) | ^~~~~~~~~~~ The problem is that f() doesn't return, but the location points to the lambda expression, which certainly does return. Clang gets it right: a.cc:6:1: warning: non-void function does not return a value [-Wreturn-type] 6 | } | ^ 1 warning generated. And EDG too: "a.cc", line 6: warning: missing return statement at end of non-void function "f" } ^