1 // RUN: %clang_cc1 -std=c++17 -fexperimental-new-constant-interpreter -verify %s
2 // RUN: %clang_cc1 -std=c++17 -verify=ref %s
4 constexpr bool isEven(int a
) {
34 static_assert(isEven(2), "");
35 static_assert(isEven(8), "");
36 static_assert(isEven(10), "");
37 static_assert(isEven(18), "");
38 static_assert(!isEven(1), "");
39 static_assert(!isEven(3), "");
42 constexpr int withInit() {
43 switch(int a
= 2; a
) {
49 static_assert(withInit() == 2, "");
51 constexpr int FT(int a
) {
63 static_assert(FT(1) == 1, "");
64 static_assert(FT(4) == 4, "");
65 static_assert(FT(5) == -1, "");
68 constexpr int good() { return 1; }
69 constexpr int test(int val
) {
71 case good(): return 100;
76 static_assert(test(1) == 100, "");
78 constexpr int bad(int val
) { return val
/ 0; } // expected-warning {{division by zero}} \
79 // ref-warning {{division by zero}}
80 constexpr int another_test(int val
) { // expected-note {{declared here}} \
81 // ref-note {{declared here}}
83 case bad(val
): return 100; // expected-error {{case value is not a constant expression}} \
84 // expected-note {{cannot be used in a constant expression}} \
85 // ref-error {{case value is not a constant expression}} \
86 // ref-note {{cannot be used in a constant expression}}
91 static_assert(another_test(1) == 100, ""); // expected-error {{static assertion failed}} \
92 // expected-note {{evaluates to}} \
93 // ref-error {{static assertion failed}} \
94 // ref-note {{evaluates to}}