Skip to content

fix(maul): check that a library's nodiscard macro is not empty in C23 - #122

Merged
siracozmen01 merged 1 commit into
mainfrom
fix/nodiscard-c23-check
Nov 5, 2026
Merged

siracozmen01 merged 1 commit into
mainfrom
fix/nodiscard-c23-check

Conversation

@siracozmen01

Copy link
Copy Markdown
Contributor

Problem

A library's <PP>_NODISCARD used 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, but maul_add_header_tests checks the macro only in C++17, so a library that went back to the old test would pass every check.

Change

  • maul_add_header_tests writes c23_nodiscard.c, which includes the library's base.h and asserts in C23 that <PP>_NODISCARD is not empty, beside the C++17 check. It builds in header_test_c23, so it is skipped where that target is (MSVC's cl).
  • maul-conventions.md says 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 -Werror against each library's headers at its current main:

  • all twelve libraries pass under gcc-14 and clang-20;
  • maul-audio's main before its fix (#355) failed under gcc-14 ("MAUD_NODISCARD is empty in C23") and passed under clang-20, which reports 202311L.

Closes #121

@siracozmen01 siracozmen01 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@siracozmen01
siracozmen01 merged commit c7b0f19 into main Nov 5, 2026
1 check failed
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.

The header tests do not check that a library's nodiscard macro is set in C23

1 participant