From bd2fe9acfba2913fb37208dafc140ea274ddc95d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 2 Sep 2026 06:53:50 +0000 Subject: [PATCH] Suppress GCC 16 false-positive -Warray-bounds warning [why] GCC 16 emits a spurious -Warray-bounds warning in SmallVector::data_end() when it is inlined through deep std::variant construction chains, such as those as those used in the doocs::Field class. Clang does not reproduce the warning, and the address sanitizer confirms that the generated code is OK. [how] Use pragmas for gcc to suppress the warning. --- include/gul17/SmallVector.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/gul17/SmallVector.h b/include/gul17/SmallVector.h index 4810da0..7c4f6c1 100644 --- a/include/gul17/SmallVector.h +++ b/include/gul17/SmallVector.h @@ -1301,6 +1301,15 @@ class SmallVector ::new(static_cast(p)) ValueType(value); } + // GCC 16's interprocedural array-bounds analysis can be confused when data_end() is + // inlined into code that constructs a SmallVector as an alternative of a + // std::variant. It then emits a false-positive "array subscript is outside array + // bounds" warning (see #57), so we silence -Warray-bounds. +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Warray-bounds" +#endif + /// Return a non-dereferenceable pointer past the last element. constexpr ValueType* data_end() noexcept { @@ -1313,6 +1322,10 @@ class SmallVector return data_ptr_ + size_; } +#if defined(__GNUC__) && !defined(__clang__) +# pragma GCC diagnostic pop +#endif + /// Deallocate aligned memory that was reserved with allocate_space_for_elements(). static void deallocate_space_for_elements(ValueType* ptr) noexcept {