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

            Bug ID: 91278
           Summary: Array arithmetic yields "is not a constant expression"
                    error
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arthur.j.odwyer at gmail dot com
  Target Milestone: ---

Bug 77911 might be related, I'm not sure.

// https://godbolt.org/z/UUb7kW
constexpr bool test() { 
    int i[2] {};
    int j[2] {};
    return i+0 == j+1;
}
constexpr bool x = test();

====
<source>:5:16: error: '(((int*)(& i)) == (((int*)(& j)) + 4))' is not a
constant expression
    5 |     return i+0 == j+1;
      |            ~~~~^~~~~~
====

There are two issues here. One is that the error shouldn't be happening at all;
it's totally cromulent to compare i+0 (i.e. &i[0]) with j+1 (i.e. &j[1]). `x`
should be initialized to `false`.

The other issue is cosmetic: this error is apparently happening very late in
the compiler, so that `j+1` (i.e. &j[1]) ends up getting pretty-printed as
`(((int*)(& j)) + 4))` (i.e. &j[4]). Seems like the compiler is remembering
SOME of the type information about `j` but not ALL of the type information.

Reply via email to