Repository navigation
fix(maul): mark the shared cpu.h's two bool functions nodiscard - #126
Conversation
siracozmen01
left a comment
There was a problem hiding this comment.
Review at ada6ddc: ready. Read, not run.
No cycle. cpu.h now includes @LIB@/base.h. base.h includes only <stdbool.h>, <stddef.h> and <stdint.h> (maul2d's at its sync head, the same shape in the family), never a src/ header, and both have include guards, so the include cannot loop.
No ordering problem.
cpu.cincludescpu.hfirst, as before.- For maul2d, maul3d and maul-anim,
base.h's unmarked@P@_API bool @P@IsCpuBackendSupported(void);now comes beforecpu.h's marked redeclaration, and before the definition incpu.c. A later declaration may add[[nodiscard]], as the body's gcc-14 and clang-20 runs show. - On Windows, a redeclaration without
__declspec(dllexport)after one with it keeps the export.
No module rule reached. check_modules.py reads only includes without a slash ("([^"/]+)\.h"), so "@LIB@/base.h" is a public header there, as its comment allows. maul2d's cpu: line needs no new edge.
One effect to know about. cpu.c's definitions now see base.h's @P@_API declaration in the three libraries where it exists. In a shared build that gives @P@IsCpuBackendSupported default visibility (or dllexport) through its definition's own translation unit. That is what @P@_API asks for, but it may change the shared library's export list where the definition was compiled without seeing it. Each library's check_exports test in its sync PR will show it. I did not build a shared tree.
The marks are right: every call in the three libraries uses the result, per the body, and a dropped one now fails at -Werror.
Problem
v0.0.53's
check_nodiscard.pyreports two unmarked bool functions in the sharedmaul/renamed/src/cpu.h:@P@IsCpuBackendSupportedand@P@CheckCpu. #124 marked the other renamed files but missed these, because the@P@placeholder hid their names from its scan. maul2d, maul3d and maul-anim carry cpu.h and cannot pass the check without editing a family file.Change
cpu.hincludes@LIB@/base.hand marks both declarations@PP@_NODISCARD. A publicbase.hthat also declares them (all three libraries do, unmarked) keeps its own declaration; the mark on this later one makes a dropped result warn inside the library.Verification
Synced from this branch into scratch trees of maul2d, maul3d and maul-anim:
src/cpu.hpassesclang-format --dry-run -Werror, andsrc/cpu.cbuilds with gcc-14 and clang-20 at-std=c23 -Wall -Wextra -Wpedantic -Werror;tools/check_nodiscard.pyno longer reports cpu.h;maniCheckCpu's result warns under gcc-14;Closes #125