Chapman Flack <chap@anastigmatix.net> writes:
> I noticed in CI builds of PL/Java with PG 13 that -Wimplicit-fallthrough=3
> in pg_config's CFLAGS was causing some switch case fallthrough warnings
> after an elog(ERROR. [1]
Yeah, I can replicate this here (gcc 8.3.1 on RHEL8). My recollection
is that we saw this when trialling -Wimplicit-fallthrough, and determined
that the hack used to teach the compiler that elog(ERROR) doesn't return
fails to prevent -Wimplicit-fallthrough warnings even though it does work
for other purposes. Using this test case:
int
foo(int p)
{
int x;
switch (p)
{
case 0:
x = 1;
break;
case 1:
elog(ERROR, "bogus");
break;
case 2:
x = 2;
break;
default:
x = 3;
}
return x;
}
I do not get a warning about x being possibly uninitialized (so it
knows elog(ERROR) doesn't return?), but without the "break" after
elog() I do get a fallthrough warning (so it doesn't know that?).
Seems like a minor gcc bug; no idea if anyone's complained to them.
I think we've found other weak spots in -Wimplicit-fallthrough's
coverage though, so it's not one of gcc's best areas.
As illustrated here, I'd just add a "break" rather than
"pg_unreachable()", but that's a matter of taste.
regards, tom lane