[Bug c/110839] New: Bogus -Wreturn-type for unreachable switch default case
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 28 07:36:04 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110839
Bug ID: 110839
Summary: Bogus -Wreturn-type for unreachable switch default
case
Product: gcc
Version: 13.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
unsigned char random_ui8(void);
int f16RandomQOutP3 (void);
int f16RandomQOutPInf (void);
int f16RandomQInfP3 (void);
int f16RandomQInfPInf (void);
int f16Random( void )
{
switch ( random_ui8() & 7 ) {
case 0:
case 1:
case 2:
return f16RandomQOutP3();
case 3:
return f16RandomQOutPInf();
case 4:
case 5:
case 6:
return f16RandomQInfP3();
case 7:
return f16RandomQInfPInf();
}
}
diagnoses
gcc -S t.c -O2 -Wreturn-type
t.c: In function 'f16Random':
t.c:23:1: warning: control reaches end of non-void function [-Wreturn-type]
23 | }
| ^
this is because pass_warn_function_return runs after lowering before any
optimization is done and the gimplifier adds a default: case that
falls through to the function end.
More information about the Gcc-bugs
mailing list