Skip to content

Don't use Clang nullability qualifiers in strict ISO C mode - #3074

Merged
soutaro merged 1 commit into
masterfrom
claude/fix-nullability-pedantic-errors
Aug 10, 2026
Merged

Don't use Clang nullability qualifiers in strict ISO C mode#3074
soutaro merged 1 commit into
masterfrom
claude/fix-nullability-pedantic-errors

Conversation

@soutaro

@soutaro soutaro commented Aug 10, 2026

Copy link
Copy Markdown
Member

_Nullable and _Nonnull are Clang extensions, so compiling the rbs headers in a strict ISO C dialect emits -Wnullability-extension, which -pedantic-errors turns into an error:

include/rbs/ast.h:166:44: error: type nullability specifier '_Nonnull' is a Clang extension [-Werror,-Wnullability-extension]
  166 | void rbs_node_list_append(rbs_node_list_t *RBS_NONNULL list, rbs_node_t *RBS_NONNULL node);
      |                                            ^
include/rbs/defines.h:93:21: note: expanded from macro 'RBS_NONNULL'
   93 | #define RBS_NONNULL _Nonnull

CRuby's omnibus compilations, #5 job builds with -std=c99 -Werror=pedantic -pedantic-errors (and c11/c17/c2x), so ext/rbs_extension fails to compile there once rbs 4.1.x is bundled — see ruby/ruby#18274. rbs 4.0.3 had no nullability macros, so this is new in 4.1.x.

Expand the macros to nothing when __STRICT_ANSI__ is defined, which is exactly the case where the qualifiers are rejected. Feature-test macros don't work here: both __has_feature(nullability) and __has_extension(nullability) report 1 even under -std=c99, since the extension is available — it just warns.

Clang's default -std=gnu* dialects keep the annotations, so nothing is lost for the static analyzer. Verified with clang 18: all of src/ compiles cleanly under c99/c11/c17/c2x with -pedantic-errors, and -std=gnu17 still expands to _Nonnull / _Nullable.

`_Nullable` and `_Nonnull` are Clang extensions, so compiling the rbs
headers in a strict ISO C dialect emits `-Wnullability-extension`, which
`-pedantic-errors` turns into an error:

    include/rbs/ast.h:166:44: error: type nullability specifier '_Nonnull' is a Clang extension [-Werror,-Wnullability-extension]
      166 | void rbs_node_list_append(rbs_node_list_t *RBS_NONNULL list, rbs_node_t *RBS_NONNULL node);
          |                                            ^
    include/rbs/defines.h:93:21: note: expanded from macro 'RBS_NONNULL'
       93 | #define RBS_NONNULL _Nonnull

This breaks embedders that build the extension with a conforming dialect.
CRuby's `omnibus compilations` CI job compiles the bundled gems with
`-std=c99 -Werror=pedantic -pedantic-errors` (and c11/c17/c2x), so
building `ext/rbs_extension` there fails once rbs is bundled.

Expand the macros to nothing when `__STRICT_ANSI__` is defined, which is
exactly the case where the qualifiers are not accepted. Non-strict builds,
including Clang's default `-std=gnu*` dialects, keep the annotations, so
nothing is lost for the static analyzer.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vqx4FeruSY2rScP3frptqZ
@soutaro
soutaro added this pull request to the merge queue Aug 10, 2026
Merged via the queue into master with commit 2beabfa Aug 10, 2026
25 checks passed
@soutaro
soutaro deleted the claude/fix-nullability-pedantic-errors branch August 10, 2026 05:26
soutaro added a commit that referenced this pull request Aug 10, 2026
Backport #3074 to 4.1: Don't use Clang nullability qualifiers in strict ISO C mode
@soutaro soutaro mentioned this pull request Aug 10, 2026
@soutaro soutaro mentioned this pull request Aug 18, 2026
soutaro pushed a commit that referenced this pull request Aug 23, 2026
`RBS::VERSION` becomes 4.2.0, `Gemfile.lock` is regenerated with the bump,
and the 4.2.0.pre.1 section of CHANGELOG.md is replaced by the 4.2.0
section that folds it in.

The changelog starts at `v4.1.2`, the latest release proper reachable from
`master`: a release proper skips the prerelease tags, so everything written
up under 4.2.0.pre.1 is in this section as well. #3074 and #3073 appear
under 4.1.3 too, which backported them.

Co-Authored-By: Claude <noreply@anthropic.com>
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