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), "");

Reply via email to