Skip to content

Commit 3515bad

Browse files
committed
Don't use Clang nullability qualifiers in strict ISO C mode
`_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)
1 parent 2c39462 commit 3515bad

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

include/rbs/defines.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@
8787
* Nullability annotations for pointer types.
8888
* Clang supports _Nullable and _Nonnull to indicate whether a pointer may be NULL.
8989
* On other compilers, these expand to nothing.
90+
*
91+
* They are Clang extensions, so a strict ISO C compilation rejects them with
92+
* `-Wnullability-extension`, which is an error under `-pedantic-errors`. Expand
93+
* them to nothing in that case, so that embedders compiling these headers with a
94+
* conforming dialect (`-std=c99` and friends define `__STRICT_ANSI__`) still build.
9095
*/
91-
#ifdef __clang__
96+
#if defined(__clang__) && !defined(__STRICT_ANSI__)
9297
#define RBS_NULLABLE _Nullable
9398
#define RBS_NONNULL _Nonnull
9499
#else

0 commit comments

Comments
 (0)