https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100365
Bug ID: 100365 Summary: bogus -Wreturn-type with a return statement with an erroneous expression Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The C front end issues a spurious -Wreturn-type warning for return statements with erroneous arguments in non-void functions. The C++ front end does a better job (and Clang better still): $ cat z.c && gcc -S -Wall z.cint f () { return x; } int g () { return (int); } int h () { return ++0; } z.c: In function ‘f’: z.c:3:10: error: ‘x’ undeclared (first use in this function) 3 | return x; | ^ z.c:3:10: note: each undeclared identifier is reported only once for each function it appears in z.c: In function ‘g’: z.c:8:15: error: expected expression before ‘;’ token 8 | return (int); | ^ z.c: In function ‘h’: z.c:13:10: error: lvalue required as increment operand 13 | return ++0; | ^~ z.c: In function ‘f’: z.c:4:1: warning: control reaches end of non-void function [-Wreturn-type] 4 | } | ^ z.c: In function ‘g’: z.c:9:1: warning: control reaches end of non-void function [-Wreturn-type] 9 | } | ^ z.c: In function ‘h’: z.c:14:1: warning: control reaches end of non-void function [-Wreturn-type] 14 | } | ^ G++ issues just the four errors below: z.c: In function ‘int f()’: z.c:3:10: error: ‘x’ was not declared in this scope 3 | return x; | ^ z.c: In function ‘int g()’: z.c:8:11: error: expected primary-expression before ‘int’ 8 | return (int); | ^~~ z.c:8:11: error: expected ‘)’ before ‘int’ 8 | return (int); | ~^~~ | ) z.c: In function ‘int h()’: z.c:13:12: error: lvalue required as increment operand 13 | return ++0; | ^ Clang: z.c:3:10: error: use of undeclared identifier 'x' return x; ^ z.c:8:15: error: expected expression return (int); ^ z.c:13:10: error: expression is not assignable return ++0; ^ ~ 3 errors generated.