Debian Codegraph @

gcc/testsuite/g++.dg/cpp26/constexpr-new3.C

raw
1 // C++26 P2747R2 - constexpr placement new
2 // { dg-do compile { target c++26 } }
3
4 #include "../cpp2a/construct_at.h"
5
6 struct S {
7 constexpr S () : a (42), b (43) {}
8 constexpr S (int c, int d) : a (c), b (d) {}
9 int a, b;
10 };
11 struct T {
12 int a, b;
13 };
14
15 constexpr bool
16 foo ()
17 {
18 std::allocator<int> a;
19 auto b = a.allocate (3);
20 new (b + 1) int[] {2, 3}; // { dg-error "" "" { xfail *-*-* } }
21 a.deallocate (b, 3);
22 return true;
23 }
24
25 constexpr bool
26 bar ()
27 {
28 std::allocator<int> a;
29 auto b = a.allocate (3);
30 new (b) int[] {1, 2, 3, 4}; // { dg-error "array subscript value '3' is outside the bounds of array 'heap ' of type 'int \\\[3\\\]'" }
31 a.deallocate (b, 3);
32 return true;
33 }
34
35 constexpr bool
36 baz ()
37 {
38 std::allocator<int> a;
39 auto b = a.allocate (2);
40 new (b) long (42); // { dg-error "accessing value of 'heap ' through a 'long int' glvalue in a constant expression" }
41 a.deallocate (b, 2);
42 return true;
43 }
44
45 constexpr bool a = foo ();
46 constexpr bool b = bar ();
47 constexpr bool c = baz ();