mirror of
https://github.com/Z3Prover/z3
synced 2026-06-13 12:25:37 +00:00
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. |
||
|---|---|---|
| .. | ||
| modules | ||
| check_link_atomic.cmake | ||
| cmake_uninstall.cmake.in | ||
| compiler_lto.cmake | ||
| compiler_warnings.cmake | ||
| cxx_compiler_flags_overrides.cmake | ||
| git_utils.cmake | ||
| msvc_legacy_quirks.cmake | ||
| target_arch_detect.cmake | ||
| target_arch_detect.cpp | ||
| z3_add_component.cmake | ||
| z3_add_cxx_flag.cmake | ||
| z3_append_linker_flag_list_to_target.cmake | ||
| Z3Config.cmake.in | ||