aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/consteval11.C
blob: c2ee3c7a82aa4b621e1959cc9fc670e904125300 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// { dg-do compile }
// Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'.
// { dg-options "-std=c++2a" }

consteval int bar (int i) { if (i != 1) throw 1; return 0; }	// { dg-error "is not a constant expression" }

constexpr int a = bar (1);
constexpr int b = bar (2);		// { dg-message "in 'constexpr' expansion of" }
constexpr int c = 0 ? bar (3) : 1;
const int d = bar (4);			// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
const int e = 0 ? bar (5) : 1;
int f = bar (1);
int g = bar (6);			// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
int h = 0 ? bar (7) : 1;

void
foo ()
{
  constexpr int a = bar (1);
  constexpr int b = bar (2);		// { dg-message "in 'constexpr' expansion of" }
  constexpr int c = 0 ? bar (3) : 1;
  const int d = bar (4);		// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  const int e = 0 ? bar (5) : 1;
  int f = bar (1);
  int g = bar (6);			// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  int h = 0 ? bar (7) : 1;		// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  h += 0 ? bar (8) : 1;			// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  if (0)
    bar (9);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  else
    bar (10);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  if (1)
    bar (11);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  else
    bar (12);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  if constexpr (0)
    bar (13);
  else
    bar (14);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  if constexpr (1)
    bar (15);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  else
    bar (16);
}

consteval int
baz ()
{
  constexpr int a = bar (1);
  constexpr int b = bar (2);		// { dg-message "in 'constexpr' expansion of" }
  constexpr int c = 0 ? bar (3) : 1;
  const int d = bar (4);
  const int e = 0 ? bar (5) : 1;
  int f = bar (1);
  int g = bar (6);
  int h = 0 ? bar (7) : 1;
  h += 0 ? bar (8) : 1;
  if (0)
    bar (9);
  else
    bar (10);
  if (1)
    bar (11);
  else
    bar (12);
  if constexpr (0)
    bar (13);
  else
    bar (14);
  if constexpr (1)
    bar (15);
  else
    bar (16);
  return 0;
}

template <typename T>
void
qux ()
{
  // Used to give errors errors here, but not since we moved consteval
  // function folding to cp_fold_r which isn't called on uninstantiated
  // templates.
  if (0)
    bar (2);
  else
    bar (3);
  if (1)
    bar (4);
  else
    bar (5);
  if constexpr (0)
    bar (6);
  else
    bar (7);
  if constexpr (1)
    bar (8);
  else
    bar (9);
  if (0)
    bar ((T) 2);
  else
    bar ((T) 3);
  if (1)
    bar ((T) 4);
  else
    bar ((T) 5);
  if constexpr (0)
    bar ((T) 6);
  else
    bar ((T) 7);
  if constexpr (1)
    bar ((T) 8);
  else
    bar ((T) 9);
}

template <typename T>
void
quux ()
{
  if (0)
    bar ((T) 2);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  else
    bar ((T) 3);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  if (1)
    bar ((T) 4);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  else
    bar ((T) 5);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  if constexpr (0)
    bar ((T) 6);
  else
    bar ((T) 7);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  if constexpr (1)
    bar ((T) 8);				// { dg-message "in 'constexpr' expansion of" }
// { dg-error "call to consteval function" "" { target *-*-* } .-1 }
  else
    bar ((T) 9);
}

void
corge ()
{
  quux <int> ();
}