https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125473

            Bug ID: 125473
           Summary: strict-overflow=4 is triggered when sorting array of
                    pointers with -std=c++20
           Product: gcc
           Version: 13.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: legoliester at gmail dot com
  Target Milestone: ---

Hi, I'm working on doctest right now to enhance support of C++20 & above.

They use aggressive warning flags for their CI.

The CI was failing on gcc-13 & std=c++20. The workaround being to simply
disable Wstrict-overflow when including <algorithm>.

Here is the gist of the bug.

Minimum viable example :
```
#include <algorithm>

struct A{};

int main() {
    A *bla[1]={nullptr};
    std::sort(bla,bla);
    return 0;
}
```

```
$ g++-13 --version
g++-13 (Ubuntu 13.4.0-10ubuntu1) 13.4.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

```
$g++-13 -Werror -Wstrict-overflow=3 -O1 -std=c++20 test.cpp
In file included from /usr/include/c++/13/bits/stl_algo.h:61,
                 from /usr/include/c++/13/algorithm:61,
                 from test.cpp:1:
In function ‘constexpr void std::__adjust_heap(_RandomAccessIterator,
_Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = A**;
_Distance = long int; _Tp = A*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’,
    inlined from ‘constexpr void std::__pop_heap(_RandomAccessIterator,
_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with
_RandomAccessIterator = A**; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’ at
/usr/include/c++/13/bits/stl_heap.h:264:25,
    inlined from ‘constexpr void std::__sort_heap(_RandomAccessIterator,
_RandomAccessIterator, _Compare&) [with _RandomAccessIterator = A**; _Compare =
__gnu_cxx::__ops::_Iter_less_iter]’ at
/usr/include/c++/13/bits/stl_heap.h:425:19,
    inlined from ‘constexpr void std::__partial_sort(_RandomAccessIterator,
_RandomAccessIterator, _RandomAccessIterator, _Compare) [with
_RandomAccessIterator = A**; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’ at
/usr/include/c++/13/bits/stl_algo.h:1911:23,
    inlined from ‘constexpr void std::__introsort_loop(_RandomAccessIterator,
_RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = A**;
_Size = long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’ at
/usr/include/c++/13/bits/stl_algo.h:1926:27:
/usr/include/c++/13/bits/stl_heap.h:229:28: error: assuming signed overflow
does not occur when changing X +- C1 cmp C2 to X cmp C2 -+ C1
[-Werror=strict-overflow]
  229 |       while (__secondChild < (__len - 1) / 2)
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
```

```
$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/";
SUPPORT_URL="https://help.ubuntu.com/";
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/";
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy";
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo
```

Reply via email to