Suppress GCC 16 false-positive -Warray-bounds warning in SmallVector::data_end()#59
Conversation
|
This is the patch I carry arround. Very similar, plus another spot. As mentioned in the issue, I had to cut the error messages, since gitlab has a length limit for text in a single entry: diff --git a/include/gul17/SmallVector.h b/include/gul17/SmallVector.h
index 4810da0..31c6f7e 100644
--- a/include/gul17/SmallVector.h
+++ b/include/gul17/SmallVector.h
@@ -1304,7 +1304,10 @@ private:
/// Return a non-dereferenceable pointer past the last element.
constexpr ValueType* data_end() noexcept
{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
return data_ptr_ + size_;
+#pragma GCC diagnostic pop
}
/// Return a non-dereferenceable pointer past the last element.
@@ -1648,7 +1651,13 @@ private:
while (src != src_end)
{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#ifndef __clang__
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+#endif
::new (static_cast<void*>(dest)) ValueType(std::move(*src));
+#pragma GCC diagnostic pop
++src;
++dest;
}Also I'm not sure if we need the extra |
Unfortunately Clang seems to emulate GCC pragmas (https://clang.llvm.org/docs/UsersManual.html):
So I propose we leave the Copilot patch as it is. I'll just make the comment more concise. Your second suppression belongs into a separate PR, I think. |
|
I guess one could ask if we should suppress the warning here or around the "problematic" use case in the clientlib. But since this particular false positive has already cost us at least 3 issues across at least two projects PLUS time discussing it, I think we should suppress it in GUL17. |
[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.
b6126dc to
bd2fe9a
Compare
|
Merged by hand, so I'll close this PR. |
GCC 16.2.1 emits spurious
-Warray-boundswarnings ingul17::SmallVector::data_end()when it's inlined through deepstd::variantconstruction chains, such as those used in DOOCS clientlib'sdoocs::Field. Clang does not reproduce the warning.Root cause
std::variant's placement-new constructors, and misattributes the pointer arithmetic indata_end()(data_ptr_ + size_) to an unrelated, smaller object.data_ptr_always points to storage sizedcapacity_(internal SBO array or heap allocation), andsize_ <= capacity_is a class invariant maintained throughout.-O2 -Wall -Wextra -Warray-bounds=2: no warnings, correct runtime behavior for move construction and SBO-heavy usage patterns.Fix
data_end()overloads ininclude/gul17/SmallVector.hwith a GCC-only#pragma GCC diagnostic push/ignored "-Warray-bounds"/pop, guarded bydefined(__GNUC__) && !defined(__clang__).include/gul17/date.h.