]> git.ipfire.org Git - thirdparty/squid.git/commit
Maintenance: Trigger -Wswitch in more build environments (#1104)
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 27 Jul 2022 18:11:52 +0000 (18:11 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 29 Jul 2022 18:23:10 +0000 (18:23 +0000)
commitbffc3a5614370621808dcd2212cbf80775524e02
treed75b48913519992966a1ca1805ccbeb9c1982fa2
parent6ea12e8fb590ac6959e9356a81aa3370576568c3
Maintenance: Trigger -Wswitch in more build environments (#1104)

When a developer forgets to update RawSwapMetaTypeTop() after adding a
new SwapMetaType item, the function should produce a -Wswitch compiler
warning (at least). However, we discovered that many compilers remain
silent, apparently confused by the constant switch expression:

* GCC warns only starting with v9.1;
* clang does not warn at all (up to v14, inclusive).

Adding a non-constant variable triggers the expected -Wswitch warnings
in clang and earlier GCC versions. Optimizing compilers (-O1) remove the
otherwise unused variable so adding it has no runtime cost.

Declaring the variable outside the switch statement is required to avoid
an unwanted -Wunused-variable warning with GCC v4.8 and clang v3.0.0.

A post-switch return statement is required to avoid an unwanted
-Wreturn-type warning with GCC v4.9.

Tests: https://gcc.godbolt.org/z/d1czs4c8e
src/store/SwapMeta.h