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

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
constexpr void foo(int* x) { ++*x; }
constexpr int bar() {
  int* x = new int(0);
  foo(x);
  foo(x);
  int y = *x;
  delete x;
  return y;
}
static_assert(bar() == 2);

We reject the above testcase for seemingly the same reason -- we cache the call
to foo(x) when we shouldn't have, because cxx_bind_parameters_in_call considers
the call's argument to be TREE_CONSTANT.


We accept the analogous testcase that doesn't use constexpr new/delete:

constexpr void foo(int* x) { ++*x; }
constexpr int bar() {
  int x = 0;
  foo(&x);
  foo(&x);
  return x;
}
static_assert(bar() == 2);

Reply via email to