Backport #3074 to 4.1: Don't use Clang nullability qualifiers in strict ISO C mode - #3075
Merged
Merged
Conversation
`_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
(cherry picked from commit e197225)
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports #3074 to the
aaa-4.1.xbranch, cherry-picked with-x._Nullableand_Nonnullare Clang extensions, so compiling the rbs headers in a strict ISO C dialect emits-Wnullability-extension, which-pedantic-errorsturns into an error:CRuby's
omnibus compilations, #5job builds with-std=c99 -Werror=pedantic -pedantic-errors(and c11/c17/c2x), soext/rbs_extensionfails 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, which makes the fix only reach CRuby through this branch.The macros expand to nothing when
__STRICT_ANSI__is defined, which is exactly the case where the qualifiers are rejected. Clang's default-std=gnu*dialects keep the annotations, so nothing is lost for the static analyzer.The cherry-pick applied cleanly with no conflicts.
Verification
clang -std=c99 -pedantic-errors -Werroronsrc/ast.cfails onaaa-4.1.xas it stands and passes with this commit, and the same holds for-std=c11and-std=c17.rake compileand a parser smoke test pass.Generated by Claude Code