view gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7a.C @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
line wrap: on
line source

// PR c++/94034
// { dg-do compile { target c++14 } }

struct A
{
  A *p = this;
  int n = 2;
  int m = p->n++;
};

constexpr A
foo()
{
  return {};
}

constexpr A
bar()
{
  A a = foo();
  a.p->n = 5;
  return a;
}

static_assert(bar().n == 5, "");

constexpr int
baz()
{
  A b = foo();
  b.p->n = 10;
  A c = foo();
  if (c.p->n != 3 || c.p->m != 2)
    __builtin_abort();
  bar();
  return 0;
}

static_assert(baz() == 0, "");

constexpr int
quux()
{
  const A d = foo();
  d.p->n++; // { dg-error "const object" }
  return 0;
}

static_assert(quux() == 0, ""); // { dg-error "non-constant" }