enable fallthrough warnings on clang
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-20T11:16:31Z
Lists: pgsql-hackers
Attachments
- 0001-Remove-useless-fallthrough-annotation.patch (text/plain) patch 0001
- 0002-Use-fallthrough-attribute-instead-of-comment.patch (text/plain) patch 0002
- 0003-Enable-Wimplicit-fallthrough-option-for-clang.patch (text/plain) patch 0003
- 0004-Fix-additional-fallthrough-warnings-from-clang.patch (text/plain) patch 0004
- 0005-Fix-additional-fallthrough-warning.patch (text/plain) patch 0005
The warnings about fallthrough in switch statements currently only work on gcc. It would be nice if they also worked on clang, and in the long run other compilers. gcc has a convention of annotation with comments, like /*fallthrough*/, but that is not available in other compilers. The standard for this is using attributes, like [[fallthrough]] in C23 and C++, and __attribute__((fallthrough)) as extensions in gcc and clang. (MSVC doesn't have anything like this in C mode, but it supports [[fallthrough]] in C++, so there is a plausible path to get this into C sometime as well.) So my proposal is that we wrap the appropriate attribute into a pg_fallthrough macro, and replace the current comments with that. There is a bit of fiddliness in setting the right compiler warning option. You need -Wimplicit-fallthrough=5 with gcc, but -Wimplicit-fallthrough with clang, but you don't want the latter with gcc, because that doesn't enforce the use of the attribute. Also, I found some places where clang warns but gcc does not, so there are patches to also fix those. (These appear to be bugs in gcc.)
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Enable -Wimplicit-fallthrough option for clang
- 0284e07599a5 19 (unreleased) landed
-
Fix additional fallthrough warning
- 3f7a0e1e55ef 19 (unreleased) landed
-
Fix additional fallthrough warnings from clang
- 3a63b76571ba 19 (unreleased) landed
-
test_cplusplusext: Add C++ pg_fallthrough test case
- 2f2c9d836373 19 (unreleased) landed
-
Use fallthrough attribute instead of comment
- 8354b9d6b602 19 (unreleased) landed
-
Remove useless fallthrough annotation
- 0c3fbb3fef1e 19 (unreleased) landed