1 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s 2 // RUN: %clang_cc1 -verify=ref %s 3 4 enum class EC : short { 5 A, B, C 6 }; 7 static_assert(static_cast<int>(EC::A) == 0, ""); 8 static_assert(static_cast<int>(EC::B) == 1, ""); 9 static_assert(static_cast<int>(EC::C) == 2, ""); 10 static_assert(sizeof(EC) == sizeof(short), ""); 11 12 constexpr EC ec = EC::C; 13 static_assert(static_cast<int>(ec) == 2, ""); 14 15 constexpr int N = 12; 16 constexpr int M = 2; 17 18 enum CE { 19 ONE = -1, 20 TWO = 2, 21 THREE, 22 FOUR = 4, 23 FIVE = N + M, 24 SIX = FIVE + 2, 25 MAX = __INT_MAX__ * 2U + 1U 26 }; 27 static_assert(ONE == -1, ""); 28 static_assert(THREE == 3, ""); 29 static_assert(FIVE == 14, ""); 30 static_assert(SIX == 16, ""); 31 32 constexpr EC testEnums() { 33 EC e = EC::C; 34 35 e = EC::B; 36 37 EC::B = e; // expected-error{{expression is not assignable}} \ 38 // ref-error{{expression is not assignable}} 39 40 return e; 41 } 42 43 constexpr EC getB() { 44 EC e = EC::C; 45 e = EC::B; 46 return e; 47 } 48 49 50 static_assert(getB() == EC::B, ""); 51 52 namespace B { 53 enum E : bool { Zero, One }; 54 static_assert((int)(E)2 == 1, ""); 55 } // namespace B 56