https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107735
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I wonder if this is because doing
constexpr const int *v1 = &array[3];
is valid and well defined.
Even clang gives two different error messages:
<source>:3:21: error: constexpr variable 'v1' must be initialized by a constant
expression
constexpr const int v1 = array[3];
^ ~~~~~~~~
<source>:3:26: note: read of dereferenced one-past-the-end pointer is not
allowed in a constant expression
constexpr const int v1 = array[3];
^
<source>:4:15: error: constexpr variable 'v2' must be initialized by a constant
expression
constexpr int v2 = array[4];
^ ~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/array:213:9:
note: cannot refer to element 4 of array of 3 elements in a constant expression
return _M_elems[__n];
^
<source>:4:20: note: in call to '&array->operator[](4)'
constexpr int v2 = array[4];
^
---- CUT ----
I do think clang's note of one-past-the-end gives more of a hint of why the
error message is different though.
And I do think GCC could add that note.