Commit acc9cbd8 for libheif
commit acc9cbd8e824420294ff5c52e0fe48103f98baca
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Thu Aug 27 02:24:42 2026 +0200
ci: don't treat gcc-16 -Warray-bounds false positives as errors
GCC 16 speculatively devirtualizes a virtual call to several candidate
targets (r16-4000, --param max-devirt-targets) and then runs
-Warray-bounds on the inlined body of a candidate whose class is larger
than the object that was actually allocated, although that branch is
guarded by a vtable check and can never be taken. In libheif this shows
up e.g. as
stl_construct.h:88:25: error: array subscript 'Box_meta[0]' is partly
outside array bounds of 'unsigned char [56]' [-Werror=array-bounds=]
for the destructor of a make_shared<color_profile_raw>() control block
in heif_image_set_raw_color_profile(), and at five more sites with all
codecs enabled. This is GCC PR 122197 (still open). It affects the
gcc-16 pre-release snapshot from the ubuntu-toolchain-r PPA used in CI
as well as the released 16.1.0 and 16.2.0 (the latter only in
examples/heif_enc.cc), and it cannot be avoided in the source, since
removing one trigger just moves the speculation to other type pairs.
Keep the warning visible but do not let it fail the build for GCC >= 16.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 65c918df..ff762721 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,16 @@ if(NOT MSVC)
add_compile_options(-Wno-error=conversion)
add_compile_options(-Wno-error=unused-parameter)
add_compile_options(-Wno-error=deprecated-declarations)
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
+ # GCC 16 speculatively devirtualizes a virtual call to several candidate targets and then runs
+ # -Warray-bounds on the inlined body of a candidate whose type is larger than the object that was
+ # actually allocated, even though that branch can never be taken at runtime. Examples are the
+ # std::shared_ptr control block destructor and virtual calls through a base class pointer:
+ # "array subscript 'Box_meta[0]' is partly outside array bounds of 'unsigned char [56]'"
+ # This is a compiler false positive (observed with GCC 16.0 snapshots, 16.1 and 16.2), so do not
+ # let it fail the build.
+ add_compile_options(-Wno-error=array-bounds)
+ endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-error=tautological-compare)
add_compile_options(-Wno-error=tautological-constant-out-of-range-compare)