Repository navigation
Stop htmb.h warning about tag helpers a file doesn't use - #8
Merged
Merged
Conversation
A file that included htmb.h and used no void tag got "make_void_tag defined but not used" from -Wunused-function, and a file with no tags got it for make_tag too, so -Werror builds failed. That's common in PlatformIO projects that include the header in several files. The five helpers the tag macros call (htmb_alloc, attrs_len, attrs_write, make_tag and make_void_tag) are now marked __attribute__((unused)) through HTMB_MAYBE_UNUSED. Only make_tag and make_void_tag warned; the other three were quiet only because those two call them. Making them static inline would also stop the warning, but clang -Os then copies them into every tag, and the test object grew from 16.5 KB to 26.9 KB. With the attribute the objects are the same size as before under GCC and clang at -O0, -Os and -O2. CI now builds c/tests/unused_helpers.c with -Werror as C and C++, once with no tags and once with normal tags only. The generated tags are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
A file that includes
htmb.hand uses no void tag gets'make_void_tag' defined but not used [-Wunused-function]. A file with no tags at all gets the same warning formake_tag. Under-Werrorthat fails the build, and PlatformIO projects that include the header in several files hit this often. GCC and clang both warn, as C and as C++.Fix: the five helpers the tag macros call (
htmb_alloc,attrs_len,attrs_write,make_tag,make_void_tag) are now marked__attribute__((unused))through a newHTMB_MAYBE_UNUSEDmacro. Onlymake_tagandmake_void_tagwarned. The other three stayed quiet only because those two call them, so they get the same marking. All changes are above the generated-tags markers, so this doesn't conflict with #7.Why not
static inline: that also stops the warning, but clang-Osthen copies the helpers into every tag:test_htmb.cobject, text bytesstatic inlineunusedattribute)With the attribute, the objects are the same size as before at -O0, -Os and -O2 under both compilers.
CI: a new step in the C job builds
c/tests/unused_helpers.cwith-Werroras gnu11 C and gnu++17 C++. It builds once with no tags and once with-DNORMAL_TAGS(normal tags, no void tag). It fails against the old header and passes with this one.library.json'ssrcDirisinclude, so PlatformIO doesn't build the new file.Checked locally (GCC 13.2, and clang 21.1 via
zig cc): the C tests as C and as C++ (142 ok),c/examples/main.c, the new step, and both repro files with no output under-Wall -Wextra. Re-running./generate_html documentation/html.json c/include/htmb.hleaves the header byte-for-byte unchanged.No version bump or tag.
🤖 Generated with Claude Code