[Bug c++/89074] valid pointer equality constexpr comparison rejected

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 18 14:18:05 GMT 2021


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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think this is another case of the same bug:

constexpr bool
test()
{
  int a[] = { 1, 2 };
  int b[] = { 3, 4 };

  if (a+0 == b+0)       // OK
    return false;

  if (a+1 == b+0)       // ERROR
    return false;

  return true;
}

static_assert( test() );


g++ -std=c++20 ce.C -c

ce.C:16:20: error: non-constant condition for static assertion
   16 | static_assert( test() );
      |                ~~~~^~
ce.C:16:20:   in 'constexpr' expansion of 'test()'
ce.C:10:11: error: '((((int*)(& a)) + 4) == ((int*)(& b)))' is not a constant
expression
   10 |   if (a+1 == b+0)       // ERROR
      |       ~~~~^~~~~~


More information about the Gcc-bugs mailing list