public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107861] New: C++ static_assert() does not honor -fwrapv, leading to compilation error
@ 2022-11-24 17:25 markus at oberhumer dot com
  2022-11-24 17:57 ` [Bug c++/107861] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: markus at oberhumer dot com @ 2022-11-24 17:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107861
           Summary: C++ static_assert() does not honor -fwrapv, leading to
                    compilation error
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: markus at oberhumer dot com
  Target Milestone: ---

C++ static_assert() does not honor -fwrapv, leading to compilation error

godbolt link: https://gcc.godbolt.org/z/Po8vc5Kex

$ g++ --version
g++ (GCC) 12.2.1 20220819 (Red Hat 12.2.1-

$ g++ -fwrapv -Wno-overflow -c test.cpp
test.cpp:7:34: error: non-constant condition for static assertion

$ cat test.cpp

// compile with: g++ -fwrapv -Wno-overflow -c test.cpp
//
// extra rant: -Wno-overflow should not be needed here!

#include <limits.h>

#define wrap_inc(x)     ((x) + 1 < (x))

constexpr int int_max = INT_MAX;

bool b0 = wrap_inc(int_max);
const bool b1 = wrap_inc(int_max);
constexpr bool b2 = wrap_inc(int_max);
static_assert(b2, ""); // works

// error: non-constant condition for static assertion
static_assert(wrap_inc(int_max), "");

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

end of thread, other threads:[~2022-11-24 21:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-24 17:25 [Bug c++/107861] New: C++ static_assert() does not honor -fwrapv, leading to compilation error markus at oberhumer dot com
2022-11-24 17:57 ` [Bug c++/107861] " pinskia at gcc dot gnu.org
2022-11-24 17:57 ` pinskia at gcc dot gnu.org
2022-11-24 18:18 ` markus at oberhumer dot com
2022-11-24 19:29 ` redi at gcc dot gnu.org
2022-11-24 19:34 ` redi at gcc dot gnu.org
2022-11-24 19:43 ` markus at oberhumer dot com
2022-11-24 20:56 ` redi at gcc dot gnu.org
2022-11-24 21:49 ` redi at gcc dot gnu.org

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).