Repository navigation
build: /WX on every MSVC target, and no more C4127 - #389
Merged
Merged
Conversation
build.bat under Visual Studio 2022 stops on error C2220 partway through the
conformance suite. 32 lines in tests/conformance.c each raise C4127,
"conditional expression is constant", and that build has carried /WX for a long
time. CI never saw it: the windows-latest runner is on Visual Studio 2026, whose
front end no longer reports C4127 for these, so main is green on the runner and
broken on a 2022 desktop.
Two macros were the whole of it. Each wrapped its cases in a runtime `if` over a
sizeof comparison the compiler folds away:
if (sizeof(type) <= sizeof(int)) { ... }
if (sizeof(int_least8_t) == sizeof(signed char)) { ... }
C has no `if constexpr` to mark that as deliberate, so the guards move to the
preprocessor, which answers the same questions from the type maxima <stdint.h>
and <limits.h> already publish: a signed type is no wider than int exactly when
its maximum fits in INT_MAX, and two integer types of one signedness hold the
same values exactly when their maxima match -- which is the property these cases
actually rest on. Grouping cases under #if is what the rest of the section does.
The other half is the policy itself. /WX is MSVC's -Werror, and three of the four
compile-only targets -- npf_static, use_npf_directly, wrap_npf -- were building
at the default warning level, so nothing they said could fail the build. They now
carry the same /W4 /WX set as the unit and conformance builds, hoisted into one
_CL_WARN_FLAGS. All three were already clean at /W4: a survey run with /WX off
found C4127 to be the only warning the entire Windows build emits, 6208 of them,
all from those 32 lines.
Verified on VS 2022 19.44.35228 across Release/x64, Release/x86 and Debug/x64:
zero warnings, and "PASSED: 3642306 assertions across 5064 objects" -- the same
count the green VS 2026 CI run reports, so the #if guards select exactly what the
runtime guards used to. clang also compiles the file clean under the Makefile's
-Wall -Wextra -Wundef -Werror in both C17 and C++20.
nanoprintf.h is untouched, so there is no code-size impact.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
build.batunder Visual Studio 2022 stops onerror C2220partway through the conformance suite. 32 lines intests/conformance.ceach raise C4127, "conditional expression is constant", and that build has carried/WXfor a long time.CI never saw it: the
windows-latestrunner is on Visual Studio 2026 (v18.9.1), whose front end no longer reports C4127 for these. Somainis green on the runner and broken on a 2022 desktop.The warnings
Two macros were the whole of it. Each wrapped its cases in a runtime
ifover asizeofcomparison the compiler folds away:C has no
if constexprto mark that as deliberate, so the guards move to the preprocessor, which answers the same questions from the type maxima<stdint.h>and<limits.h>already publish:intexactly when its maximum fits inINT_MAXsizeofequality doesGrouping cases under
#ifis what the rest of that section already does. Both macros lose a parameter and a nesting level as a result.The policy
/WXis MSVC's-Werror, and three of the four compile-only targets —npf_static,use_npf_directly,wrap_npf— were building at the default warning level, so nothing they said could fail the build. They now carry the same/W4 /WXset as the unit and conformance builds, hoisted into one_CL_WARN_FLAGSso the policy lives in a single place.All three were already clean at
/W4. A survey run with/WXoff across the whole matrix found C4127 to be the only warning the entire Windows build emits — 6208 of them, all from those 32 lines.Verification
VS 2022
19.44.35228, full 2532-combo matrix, no shard:error C2220, exit 1All three report
PASSED: 3642306 assertions across 5064 objects— the same count the green VS 2026 CI run reports, so the#ifguards select exactly what the runtime guards used to and no coverage was traded away.clangalso compiles the file clean under the Makefile's-Wall -Wextra -Wundef -Werrorin both C17 and C++20;-Wundefconfirms every macro in the new#iflines is actually defined.nanoprintf.his untouched, so there is no code-size impact — cortex-m0/m4-Osoutput is unchanged by construction.🤖 Generated with Claude Code