Repository navigation
fix(maul): check that a library's nodiscard macro is not empty in C23 - #122
Conversation
siracozmen01
left a comment
There was a problem hiding this comment.
Review at 528d93b: ready. Read, not run.
c23_nodiscard.c is written in the same branch as the C++17 file, so it exists whenever base.h has a column-0 #define <PP>_NODISCARD [[nodiscard]]. That line stays in a library that goes back to the old >= 202311L test, so a regression is still checked. The generated file is the C++ one with "C23" in its message. It goes into maul_c23_sources, which header_test_c23 builds with C_STANDARD 23 and the family's -Wall -Wextra -Wpedantic -Werror. Like the per-header C23 files, it is left out only under MSVC's cl (CMAKE_C_COMPILER_ID STREQUAL "MSVC"). clang-cl still gets it through /clang:-std=c23. The check is independent of a C++ compiler, which matches the comment's "Without a C++ compiler the C++ checks are skipped".
The assertion can fail: an empty macro stringizes to "", size 1. That is the body's maul-audio pre-fix result under gcc-14.
The comment and the maul-conventions.md line describe the C rule as the libraries now write it. I did not run docs_check.py, since the local checkout is not at this head.
Problem
A library's
<PP>_NODISCARDused to take[[nodiscard]]in C only from__STDC_VERSION__ >= 202311L. GCC 14 reports its C23 mode as 202000L, so under GCC 14 the macro was empty and a program that dropped a status got no warning. Every library has now taken maul-locale's fixed block, butmaul_add_header_testschecks the macro only in C++17, so a library that went back to the old test would pass every check.Change
maul_add_header_testswritesc23_nodiscard.c, which includes the library'sbase.hand asserts in C23 that<PP>_NODISCARDis not empty, beside the C++17 check. It builds inheader_test_c23, so it is skipped where that target is (MSVC'scl).maul-conventions.mdsays how the macro reads C dialects and that the header tests check it in C23 and C++17.Verification
The generated file, compiled with
-std=c23 -Wall -Wextra -Wpedantic -Werroragainst each library's headers at its current main:Closes #121