Skip to content

Stop htmb.h warning about tag helpers a file doesn't use - #8

Merged
oklar merged 1 commit into
mainfrom
pr/reverent-cerf-128081
Oct 28, 2026
Merged

oklar merged 1 commit into
mainfrom
pr/reverent-cerf-128081

Conversation

@oklar

@oklar oklar commented Oct 28, 2026

Copy link
Copy Markdown
Owner

A file that includes htmb.h and 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 for make_tag. Under -Werror that 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 new HTMB_MAYBE_UNUSED macro. Only make_tag and make_void_tag warned. 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 -Os then copies the helpers into every tag:

test_htmb.c object, text bytes GCC -Os clang -Os clang -O2
before 16184 16478 31887
static inline 16184 26868 33962
this PR (unused attribute) 16184 16478 31887

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.c with -Werror as 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's srcDir is include, 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.h leaves the header byte-for-byte unchanged.

No version bump or tag.

🤖 Generated with Claude Code

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>
@oklar
oklar merged commit 754c3a8 into main Oct 28, 2026
6 checks passed
@oklar oklar mentioned this pull request Oct 28, 2026
@oklar
oklar deleted the pr/reverent-cerf-128081 branch October 28, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant