Skip to content

gh-162182: Fix c-analyzer on static_assert containing a comma - #162186

Open
cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:c_analyzer_bitfield_parens
Open

cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:c_analyzer_bitfield_parens

Conversation

@cmaloney

@cmaloney cmaloney commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

With -std=c99, glibc expands static_assert(cond, msg) to a declaration that has cond in a struct bitfield size. For example

static_assert(offsetof(T, m) >= 1, "msg");

is preprocessed to

extern int (*__Static_assert_function (void))
  [!!sizeof (struct { int __error_if_negative:
    (__builtin_offsetof (T, m) >= 1) ? 2 : -1; })];

The parser ended the size at the first comma, the one in "(T, m)", which left it out of sync and make check-c-globals failed with "too many lines".

Let a bitfield size containing parentheses run to the ";".

With -std=c99, glibc expands `static_assert(cond, msg)` to a declaration
that has cond in a struct bitfield size.  For example

    static_assert(offsetof(T, m) >= 1, "msg");

is preprocessed to

    extern int (*__Static_assert_function (void))
      [!!sizeof (struct { int __error_if_negative:
        (__builtin_offsetof (T, m) >= 1) ? 2 : -1; })];

The parser ended the size at the first comma, the one in "(T, m)",
which left it out of sync and `make check-c-globals` failed with
"too many lines".

Let a bitfield size containing parentheses run to the ";".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant