mirror of
https://github.com/Z3Prover/z3
synced 2026-06-13 12:25:37 +00:00
Towards clean z3 build in clang-tidy: Eliminate zero-length-array warnings. (#9800)
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. This one concerns "-Wzero-length-array". Many classes in Z3 use the "trailing array" idiom: the last field of the class C is a zero-length array of some type T, and the allocation of an instance adds extra space for some number of T's (usually the number is held in some other field of C). When the flag -Wzero-length-array is used, this gives warnings like: ``` warning: zero size arrays are an extension [-Wzero-length-array] ``` This PR first adds -Wzero-length-array to the CLANG_ONLY_WARNINGS defined in compiler_warnings.cmake. This causes the warnings to occur in a normal clang Z3 build. We then make a trailing_array.h, that defines a TRAILING_ARRAY(type, field) macro. This is defined, on per-comnpiler basis, to disable such warnings if they're enabled. I chose this route because the use of the idiom is baked deeply into Z3, so it didn't seem feasable to consider alternative patterns (like, for example, having the trailing field be a pointer to a separately allocated array). The rest of the changes in the PR are uses of this include file and macro in place of "raw" zero-length arrays. With these changes, all instances of this warning are removed.
This commit is contained in:
parent
054d71455d
commit
e05ebe8bef
1 changed files with 8 additions and 0 deletions
|
|
@ -9,9 +9,17 @@ set(GCC_ONLY_WARNINGS "")
|
|||
# Disable C++98 compatibility warnings to prevent excessive warning output
|
||||
# when building with clang-cl or when -Weverything is enabled.
|
||||
# These warnings are not useful for Z3 since it requires C++20.
|
||||
#
|
||||
# The "-Wno-zero-length-array" is for cases where Z3 is fetched by a CMake build
|
||||
# to serve as a component in another system. Z3 has many classes whose last member
|
||||
# is a zero-length array of some type T, indicating a variable-length array of T.
|
||||
# If the including system compiles with "-Wzero-length-array", there will be
|
||||
# many warnings. Overriding this prevents such warnings in the Z3 portion of the
|
||||
# build of the including system.
|
||||
set(CLANG_ONLY_WARNINGS
|
||||
"-Wno-c++98-compat"
|
||||
"-Wno-c++98-compat-pedantic"
|
||||
"-Wno-zero-length-array"
|
||||
)
|
||||
set(MSVC_WARNINGS "/W3")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue