1 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
2 // RUN: %clang_cc1 -std=c++14 -verify=ref %s
3 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify=expected-cpp20 %s
4 // RUN: %clang_cc1 -std=c++20 -verify=ref %s
14 static_assert(f() == 0, "");
24 static_assert(f2() == 5, "");
36 static_assert(f3() == 5, "");
48 static_assert(f4() == 5, "");
51 constexpr int f5(bool b
) {
79 static_assert(f5(true) == 8, "");
80 static_assert(f5(false) == 5, "");
83 /// FIXME: This is an infinite loop, which should
91 namespace DoWhileLoop
{
100 static_assert(f() == 1, "");
109 static_assert(f2() == 5, "");
121 static_assert(f3() == 5, "");
132 static_assert(f4() == 5, "");
134 constexpr int f5(bool b
) {
162 static_assert(f5(true) == 8, "");
163 static_assert(f5(false) == 5, "");
165 #if __cplusplus >= 202002L
174 static_assert(f6() == 5, "");
178 /// FIXME: This is an infinite loop, which should
194 static_assert(f() == 0, "");
198 for (int i
= 0; i
< 10; i
= i
+ 1){
203 static_assert(f2() == 9, "");
207 for (; i
!= 5; i
= i
+ 1);
210 static_assert(f3() == 5, "");
222 static_assert(f4() == 5, "");
233 static_assert(f5() == 5, "");
235 constexpr int f6(bool b
) {
245 for (; i
!= 10; i
= i
+ 1) {
261 static_assert(f6(true) == 8, "");
262 static_assert(f6(false) == 5, "");
265 /// FIXME: This is an infinite loop, which should
274 namespace RangeForLoop
{
275 constexpr int localArray() {
283 static_assert(localArray() == 10, "");
285 constexpr int localArray2() {
288 for(const int &i
: a
) {
293 static_assert(localArray2() == 10, "");
295 constexpr int nested() {
297 for (const int i
: (int[]){1,2,3,4}) {
305 static_assert(nested() == 20, "");
307 constexpr int withBreak() {
309 for (const int &i
: (bool[]){false, true}) {
316 static_assert(withBreak() == 1, "");
318 constexpr void NoBody() {
319 for (const int &i
: (bool[]){false, true}); // expected-warning {{empty body}} \
320 // expected-note {{semicolon on a separate line}} \
321 // expected-cpp20-warning {{empty body}} \
322 // expected-cpp20-note {{semicolon on a separate line}} \
323 // ref-warning {{empty body}} \
324 // ref-note {{semicolon on a separate line}}
329 constexpr int foo() {
333 for (int i
= 0;i
< 10;++i
) {
353 static_assert(foo() == 14, "");