aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C
blob: 832782e1427fc8dbb4a1ff74cd56b2d1b9047570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// PR c++/93633
// { dg-do compile { target c++20 } }
// { dg-additional-options "-fdelete-null-pointer-checks" }

struct A {
  constexpr A () : a (0) {}
  constexpr virtual int foo () { return 1 + a * 4; }
  int a;
};

struct B : A {
  constexpr B () : b (0) {}
  constexpr virtual int foo () { return 0 + b * 4; }
  int b;
};

constexpr int
foo ()
{
  A *a = new B ();  // { dg-message "allocated here" }
  a->a = 4;
  delete a;
  int r = a->foo ();  // { dg-error "constant expression" }
  return r;
}

constexpr auto a = foo ();  // { dg-message "in .constexpr. expansion" }