#1086677 g++-14: spurious -Warray-bounds when calling std::sort on structure whose length < 16

Package:
g++-14
Source:
g++-14
Description:
GNU C++ compiler
Submitter:
Lionel Elie Mamane
Date:
2024-11-03 18:06:02 UTC
Severity:
normal
#1086677#5
Date:
2024-11-03 18:01:57 UTC
From:
To:
1) Consider a program with a known-at-compile length structure of
   length strictly less than 16, e.g. an array.

2) Call std::sort on it in a way that, at execution time, ensures the
   arguments are within the bounds of the structure, but so that g++
   cannot statically guarantee it; e.g. the end position is determined
   by a call to a function in another compilation unit, in a library,
   ...

g++ +Warray-bounds emits a warning on libstdc++ std::sort code,
because it has a branch calling a different algorithm on the first 16
elements and on the rest, from /usr/include/c++/14/bits/stl_algo.h

  enum { _S_threshold = 16 };