]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Avoid bogus -Walloc-size-larger-than warning in test [PR116212]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 1 Apr 2025 10:02:43 +0000 (11:02 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 1 Apr 2025 10:07:17 +0000 (11:07 +0100)
The compiler can't tell that the vector size fits in int, so it thinks
it might overflow to a negative value, which would then be a huge
positive size_t.  In reality, the vector size never exceeds five.

There's no warning on trunk, so just change the local variable to use
type unsigned so that we get rid of the warning on the branches.

libstdc++-v3/ChangeLog:

PR libstdc++/116212
* testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc:
Use unsigned for vector size.

libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc

index 62f933137d26fac49f8d8556bd2e77e66e4636a1..a9f7bbf0eb71d88d0f0930f8b1b1fb540d5f6743 100644 (file)
@@ -50,7 +50,7 @@ test01(std::vector<T> ix)
     {
       ix = saved_ix;
 
-      int size = ix.size();
+      unsigned size = ix.size();
       auto buffer = std::unique_ptr<char[]>(new char[sizeof(T)*size]);
       std::span<T> rx((T *)buffer.get(), size);