1 // RUN: %clang_cc1 -std=c++17 -fexperimental-new-constant-interpreter -verify=expected,both %s
2 // RUN: %clang_cc1 -std=c++17 -verify=ref,both %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; } // both-warning {{division by zero}}
79 constexpr int another_test(int val
) { // both-note {{declared here}}
81 case bad(val
): return 100; // both-error {{case value is not a constant expression}} \
82 // both-note {{cannot be used in a constant expression}}
87 static_assert(another_test(1) == 100, ""); // both-error {{static assertion failed}} \
88 // both-note {{evaluates to}}