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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
#define N 3
constexpr bool
foo ()
{
  int *v = new int[N];
  auto p = &v[N+1];
  bool t = &v[0] == p;
  delete[] v;
  return t;
}

static_assert (!foo ());

constexpr bool
bar ()
{
  int v[N];
  auto p = &v[N+1];
  bool t = &v[0] == p;
  return t;
}
static_assert (!bar ());

The difference is that in the bar case, there is cxx_eval_array_reference
called which diagnoses this.  But in the foo case we should I think diagnose
this in cxx_eval_binary_expression when handling POINTER_PLUS_EXPR, the lhs is
(int *) &heap []
where heap [] is an artificial VAR_DECL which has int[1][3] type, and the
second operand evaluates to 16 (i.e. 4 * sizeof (int)), so this is clearly out
of bounds pointer arithmetics.

Reply via email to