https://github.com/python/cpython/commit/abbfbce57bc24afc72704616b14d29a380ccdda7
commit: abbfbce57bc24afc72704616b14d29a380ccdda7
branch: main
author: Cody Maloney <[email protected]>
committer: cmaloney <[email protected]>
date: 2026-11-18T15:13:17-08:00
summary:

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

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 <[email protected]>

files:
M Tools/c-analyzer/c_parser/parser/_regexes.py

diff --git a/Tools/c-analyzer/c_parser/parser/_regexes.py 
b/Tools/c-analyzer/c_parser/parser/_regexes.py
index c1a8ab3ad2f15da..65fe2f929a942e3 100644
--- a/Tools/c-analyzer/c_parser/parser/_regexes.py
+++ b/Tools/c-analyzer/c_parser/parser/_regexes.py
@@ -340,7 +340,10 @@ def _ind(text, level=1, edges='both'):
                     # This is actually a "constant expression".
                     \d+
                     |
-                    [^'",}}]+
+                    [^'",(}}]+
+                    |
+                    # Parens may hold commas (e.g. from offsetof()).
+                    [^'";}}]+ (?= ; )
                  )
              )?
             \s*

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to