Skip to content

Build headers as ISO C11 - #35

Merged
serprex merged 1 commit into
ClickHouse:mainfrom
iliaal:ch-c11-initializers
Nov 22, 2026
Merged

serprex merged 1 commit into
ClickHouse:mainfrom
iliaal:ch-c11-initializers

Conversation

@iliaal

@iliaal iliaal commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

The portability shim says consumers may build under any -std >= c11. Two things break that under -std=c11 -Wpedantic.

  • The implementation uses empty initializers (= {}, (chc__fields) {}), which are a C23 and GNU extension.
  • GCC defines __has_c_attribute in C11 mode too, so CHC_NODISCARD, CHC_MAYBE_UNUSED and CHC_FALLTHROUGH expand to [[...]], which C11 doesn't have.

With -pedantic-errors, the build fails.

Initializers are now {0}. CHC__HAS_ATTR only reports attributes at STDC_VERSION >= 202311L, so earlier modes use the existing GNU spellings. With GCC 11+ that means CHC_NODISCARD becomes warn_unused_result, which a (void) cast does not silence, the same as GCC before 11 and clang already get in C11 mode. CHC_FALLTHROUGH gets a attribute((fallthrough)) fallback, so -Wimplicit-fallthrough stays quiet under -Wextra.

The new test_c11 includes every header with the implementation and promotes -Wpedantic diagnostics to errors. On main it stops with 36 errors under GCC 13 and 14 under clang 14.

The shim promises any -std >= c11, but the implementation used empty
initializers, a C23 & GNU extension, & GCC reports __has_c_attribute in
C11 mode, so CHC_NODISCARD & friends expanded to [[...]]. -std=c11
-Wpedantic warns on every use, & -pedantic-errors fails the build: the
new test_c11 stops with 36 errors under GCC 13 before this change.

Use {0}, & only take the [[...]] spellings at C23, falling back to the
GNU attributes otherwise. CHC_FALLTHROUGH gains the GNU spelling so
-Wimplicit-fallthrough stays quiet.
@serprex
serprex merged commit 8094a1f into ClickHouse:main Nov 22, 2026
1 check passed
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.

2 participants