include: share covered-switch pragmas [#3595] - #3599
Conversation
Move the repeated GCC and Clang diagnostic push/pop sequence for exhaustive switches with defensive default clauses into intentionally repeat-includable paired headers. Replace only the 41 regions that use the same suppression family and distribute the headers as private build inputs. Leave the mixed -Wswitch-enum case and compiler-specific regions local. Refs networkupstools#3595 AI assistance: OpenAI Codex gpt-5.6-sol was used for repository analysis, implementation, review, drafting and validation with high reasoning. The human contributor remains responsible for the contribution. Signed-off-by: user01010111 <lapses.50.booster@icloud.com>
|
A ZIP file with standard source tarball and another tarball with pre-built docs for commit 2978188 is temporarily available: NUT-tarballs-PR-3599.zip. |
|
✅ Build nut 2.8.5.5163-master completed (commit 756e15e844 by @)
|
…les [networkupstools#3599] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
|
✅ Build nut 2.8.5.5166-master completed (commit 96d7de5c85 by @jimklimov)
|
|
✅ Build nut 2.8.5.5167-master completed (commit f816b2d532 by @jimklimov)
|
|
Strongly approve this PR. These pragmas were added during a project refactor campaign called "fightwarn" with the goal of suppressing all compiler warnings. Unfortunately, because it was rushed, the fixes themselves are often "brute-force" in nature. If the compiler says there's an integer overflow, the fix was to cast all possible integer values instead of fix the location of the overflow. If the compiler says there's a buffer overflow (even to a compiler false-positive), the fix was to add range-checked in all locations where the value is used, rather than fixing the logic. For example, one commit was introduced to the driver I maintain to suppress an integer overflow warning: crc16_recv = (uint16_t)((uint16_t)(ident_response_end[0]) << 8) | (uint16_t)(ident_response_end[1]);I later reverted this change because it was clearly an overfix. These GCC pragmas are my most disliked commits during the fix. If these changes were subject to review of the maintainer of the respective drivers, I would have rejected them in my driver immediately. Sharing them into a standard header is a choice that I would make from the beginning, if the I don't understand why the copy-and-paste approach was used in the first place. |
|
I dislike the screenfulls of these pragmas sprinkled over the code too, and kick myself for not thinking about the include-file approach earlier :) As for keeping the warnings quiet, they are mostly (hopefully) due to sort-of-overkill in range checks that may be pointless in specific-bitness builds, but may vary between platforms (OTOH, like checking I hope there was not too much brute-forcing per se, although it is possible that attention meandered and some corners got cut as hundreds of very similar cases were addressed by hand or mass replacement patterns... |
Summary
This moves the repeated GCC and Clang warning suppression around defensive
default:clauses intonut-pragmas-covered-switch-default.hand its paired-end.hheader. The headers are intentionally repeat-includable and aredistributed as private build inputs.
The change replaces 41 identical regions across 21 C and C++ translation
units. It does not alter any
switch,case, ordefaultbody.Related to #3595. This is one exact warning-family slice and does not close
the broader issue.
Scope
This deliberately leaves the following distinct cases local:
include/nutipc.hpp-Wswitch-enumblock indrivers/apcmicrolink.cdrivers/tripplite_usb.c,drivers/powerp-bin.c,drivers/adelsystem_cbi.c, anddrivers/generic_modbus.cNo other warning-suppression family is generalised in this PR.
Validation
-Werror: full clean build passed.-Werror: full clean buildpassed.
available Modbus, Avahi, neon, libusb, nutconf, C, and C++ paths.
of the warning state after each closing include.
make stylecheck,make check-source-nonascii, and whitespace checkspassed.
distcheck-lightrun withCHECK_FILES_QUICK_TARGETS=andSPELLCHECK_ERROR_FATAL=nopassed, including packaging, install,uninstall, and distclean checks. The candidate-specific quick checks were
run separately as listed above.
The Clang hard warning profile stops on 14 warnings treated as errors: ten
existing conversion warnings in
common/common.cand four existing globalconstructor warnings in
common/nutwriter.cpp. Compiling pristine source atthe same revision reproduced the same diagnostics.
An ordinary
distcheck-lightrun is also stopped by existing Aspell findingsin unchanged
NEWS.adocanddocs/man/apcmicrolink.txt. Those files matchthe base revision byte-for-byte.
Local validation did not exercise Powerman, IPMI, GPIO, Modbus RTU USB,
macOS, or Windows paths. Upstream CI remains responsible for broader platform
coverage.
AI assistance
OpenAI Codex gpt-5.6-sol was used for repository analysis, implementation,
review, drafting, and validation with high reasoning. The human contributor
remains responsible for the contribution.