public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103618] New: constexpr std::reverse produces strict-overflow warning
@ 2021-12-08 11:43 maik.urbannek at cattatech dot de
  2021-12-08 17:15 ` [Bug c++/103618] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: maik.urbannek at cattatech dot de @ 2021-12-08 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103618
           Summary: constexpr std::reverse produces strict-overflow
                    warning
           Product: gcc
           Version: og11 (devel/omp/gcc-11)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maik.urbannek at cattatech dot de
  Target Milestone: ---

(error.cpp)
```cpp
#include <algorithm>
#include <array>
#include <cstdio>

constexpr static std::array<char,4> foo()
{
    std::array<char,4> raw={'\0','a','b','c'};
    std::reverse(raw.begin(), raw.end());
    return raw;
}

int main() {
    constexpr std::array<char,4> a=foo();
    puts(a.data());
    return 0;
}
```

command
`gcc -o error error.cpp -std=c++20 -Werror=strict-overflow`

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/103618] constexpr std::reverse produces strict-overflow warning
  2021-12-08 11:43 [Bug c++/103618] New: constexpr std::reverse produces strict-overflow warning maik.urbannek at cattatech dot de
@ 2021-12-08 17:15 ` pinskia at gcc dot gnu.org
  2021-12-08 18:31 ` redi at gcc dot gnu.org
  2021-12-08 19:46 ` maik.urbannek at cattatech dot de
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-08 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-12-08
      Known to fail|                            |10.1.0
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/103618] constexpr std::reverse produces strict-overflow warning
  2021-12-08 11:43 [Bug c++/103618] New: constexpr std::reverse produces strict-overflow warning maik.urbannek at cattatech dot de
  2021-12-08 17:15 ` [Bug c++/103618] " pinskia at gcc dot gnu.org
@ 2021-12-08 18:31 ` redi at gcc dot gnu.org
  2021-12-08 19:46 ` maik.urbannek at cattatech dot de
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-08 18:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a strange one. If that overflow happened during constant evaluation, it
would be ill-formed. And none of the lines mentioned in the diagnostics have
any pointer arithmetic at all.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/103618] constexpr std::reverse produces strict-overflow warning
  2021-12-08 11:43 [Bug c++/103618] New: constexpr std::reverse produces strict-overflow warning maik.urbannek at cattatech dot de
  2021-12-08 17:15 ` [Bug c++/103618] " pinskia at gcc dot gnu.org
  2021-12-08 18:31 ` redi at gcc dot gnu.org
@ 2021-12-08 19:46 ` maik.urbannek at cattatech dot de
  2 siblings, 0 replies; 4+ messages in thread
From: maik.urbannek at cattatech dot de @ 2021-12-08 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Maik Urbannek <maik.urbannek at cattatech dot de> ---
The `constexpr` in the main function is not necessary to produce the warning. 

The Function foo has to be constexpr. 'inline' or 'static' (before the
function) does not produce the warning.

Maybe `constexpr` functions have better optimization and in one of the
optimizations happens unwanted stuff.

I don't think it is an compile-time/run-time issue.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-08 19:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08 11:43 [Bug c++/103618] New: constexpr std::reverse produces strict-overflow warning maik.urbannek at cattatech dot de
2021-12-08 17:15 ` [Bug c++/103618] " pinskia at gcc dot gnu.org
2021-12-08 18:31 ` redi at gcc dot gnu.org
2021-12-08 19:46 ` maik.urbannek at cattatech dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).