3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-08-02 12:13:25 +00:00

Fix uses of gnu anonymous structs. (#10345)

This is another PR towards the goal of getting Z3 to compile cleanly
when included via FetchContents into clang-tidy, which uses a pretty
strict set of warnings. (1 more flag after this!)

This one adds the flag -Wgnu-anonymous-struct. Z3 uses this anonymous
struct idiom, usually when using a struct as one of the members of a
union, as in:
```
            union {
                justification *        m_js;
                unsigned               m_lidx;
                struct {
                    enode *            m_lhs;
                    enode *            m_rhs;
                };
            };
```
This is not, strictly speaking, legal C++ (at least according to
Google's AI summary -- and the existence of this flag in Clang implies
that it is a GNU extension). You need to give the struct a member name
in the outer union to prevent the warning.

I'm of two minds on this. On the one hand it's not hurting anything, and
all the major compilers seem to support the idiom. On the other hand,
well, why do we have standards if we're going to ignore them in favor of
de-facto standards?

I submit this PR to show the size of the changes necessary to eliminate
the use of the extension. Personally, I'd do it, but I would gladly
withdraw the PR in favor of one that just silences the warning, if that
was the reviewer's preference.
This commit is contained in:
davedets 2026-08-01 11:44:01 -07:00 committed by GitHub
parent 90c401c5f2
commit b902c020ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 59 additions and 54 deletions

View file

@ -30,6 +30,7 @@ set(CLANG_ONLY_WARNINGS
"-Wignored-qualifiers"
"-Wnoctad-maybe-unsupported"
"-Wdeprecated-copy-with-user-provided-copy"
"-Wgnu-anonymous-struct"
)
set(MSVC_WARNINGS "/W3")