Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/consteval-prop14.C

raw
1 // P2564R3
2 // { dg-do compile { target c++20 } }
3 // Test more CALL_EXPRs in a function, some of which are escalating.
4
5 consteval int id (int i) { return i; }
6 constexpr int neg (int i) { return -i; }
7 constexpr int foo (auto i) { return id (i); }
8
9 constexpr int
10 f1 (auto i)
11 {
12 auto x = id (i); // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .id\\(i\\)." }
13 auto y = neg (i);
14 return x + y;
15 }
16
17 constexpr int
18 f2 (auto i)
19 {
20 return neg (id (i)); // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .id\\(i\\)." }
21 }
22
23 constexpr int
24 f3 (auto i)
25 {
26 auto x = i + neg (neg (neg (id (neg (neg (i)))))); // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .id\\(neg\\(neg\\(i\\)\\)\\)." }
27 return x;
28 }
29
30 constexpr int
31 f4 (auto i)
32 {
33 return i + neg ((id (2 * i) + neg (i)) / 2); // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .id\\(\\(i \\* 2\\)\\)." }
34 }
35
36 constexpr int
37 f5 (auto i)
38 {
39 (void) neg (i);
40 (void) neg (i);
41 (void) neg (i);
42 (void) neg (i);
43 (void) neg (i);
44 (void) neg (i);
45 (void) +id (i); // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .id\\(i\\)." }
46 (void) neg (i);
47 return i;
48 }
49
50 constexpr int
51 f6 (auto i)
52 {
53 auto x = neg (i + foo (i)); // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .foo<int>\\(i\\)." }
54 return x;
55 }
56
57 void
58 g (int i)
59 {
60 f1 (i); // { dg-error "call to consteval function .f1<int>\\(i\\). is not a constant expression" }
61 // { dg-error ".i. is not a constant expression" "" { target *-*-* } .-1 }
62 f1 (42);
63 f2 (i); // { dg-error "call to consteval function .f2<int>\\(i\\). is not a constant expression" }
64 // { dg-error ".i. is not a constant expression" "" { target *-*-* } .-1 }
65 f2 (42);
66 f3 (i); // { dg-error "call to consteval function .f3<int>\\(i\\). is not a constant expression" }
67 // { dg-error ".i. is not a constant expression" "" { target *-*-* } .-1 }
68 f3 (42);
69 f4 (i); // { dg-error "call to consteval function .f4<int>\\(i\\). is not a constant expression" }
70 // { dg-error ".i. is not a constant expression" "" { target *-*-* } .-1 }
71 f4 (42);
72 f5 (i); // { dg-error "call to consteval function .f5<int>\\(i\\). is not a constant expression" }
73 // { dg-error ".i. is not a constant expression" "" { target *-*-* } .-1 }
74 f5 (42);
75 f6 (i); // { dg-error "call to consteval function .f6<int>\\(i\\). is not a constant expression" }
76 // { dg-error ".i. is not a constant expression" "" { target *-*-* } .-1 }
77 f6 (42);
78 }