gcc -Wimplicit-fallthrough and pg_unreachable

From: Chapman Flack <chap(at)anastigmatix(dot)net>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: gcc -Wimplicit-fallthrough and pg_unreachable
Date: 2020-11-28 16:10:59
Message-ID: 5FC27693.9090505@anastigmatix.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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]

I added my own pg_unreachable() after the elog(ERROR, ...) calls [2]
and that did away with the warnings.

But it looks odd, and shouldn't it be unnecessary if elog is supplying
its own pg_unreachable() in the elevel >= ERROR case? [3]

Has anyone else seen this behavior? Am I doing something that stops gcc
from recognizing ERROR as a compile-time constant? Is it just a gcc bug?

(Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 seems to be the gcc version on the
Travis runner.

Regards,
-Chap

[1] https://travis-ci.com/github/tada/pljava/jobs/447208803#L694

AFAICT, the #L694 doesn't really take you to line 694 in a Travis log
because they collapse lines so the browser will not see the anchor,
so one must click to expand the containing line range first. Irksome.
Copied below.

[2]
https://github.com/tada/pljava/blame/2c8d992/pljava-so/src/main/c/type/Type.c#L246

[3]
https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/utils/elog.h;h=a16f925#l104

In file included from /usr/include/postgresql/13/server/postgres.h:47:0,
from
/home/travis/build/tada/pljava/pljava-so/src/main/c/type/Type.c:13:
/usr/include/postgresql/13/server/utils/elog.h:125:5: warning: this
statement may fall through [-Wimplicit-fallthrough=]
do { \
^
/usr/include/postgresql/13/server/utils/elog.h:145:2: note: in expansion of
macro ‘ereport_domain’
ereport_domain(elevel, TEXTDOMAIN, __VA_ARGS__)
^~~~~~~~~~~~~~
/usr/include/postgresql/13/server/utils/elog.h:215:2: note: in expansion of
macro ‘ereport’
ereport(elevel, errmsg_internal(__VA_ARGS__))
^~~~~~~
/home/travis/build/tada/pljava/pljava-so/src/main/c/type/Type.c:256:3: note:
in expansion of macro ‘elog’
elog(ERROR, "COERCEVIAIO not implemented from (regtype) %d to %d",
^~~~
/home/travis/build/tada/pljava/pljava-so/src/main/c/type/Type.c:258:2: note:
here
case COERCION_PATH_ARRAYCOERCE:
^~~~

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-11-28 16:48:17 Re: gcc -Wimplicit-fallthrough and pg_unreachable
Previous Message Drouvot, Bertrand 2020-11-28 11:08:24 Re: Add Information during standby recovery conflicts