|
| 1 | +// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s -verify |
| 2 | +// RUN: %clang_cc1 -std=c++14 -fsyntax-only %s -verify |
| 3 | +// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify |
| 4 | + |
| 5 | + |
| 6 | +namespace ScopedEnumerations { |
| 7 | + |
| 8 | +template <typename T> |
| 9 | +struct S1 { |
| 10 | + enum class E : T; |
| 11 | +}; |
| 12 | + |
| 13 | +template <typename T> |
| 14 | +enum class S1<T>::E : T { |
| 15 | + S1_X = 0x123 |
| 16 | +}; |
| 17 | + |
| 18 | +static_assert(static_cast<int>(S1<int>::E::S1_X) == 0x123, ""); |
| 19 | + |
| 20 | +template <typename T> |
| 21 | +struct S2 { |
| 22 | + static constexpr T f(int) { return 0; }; |
| 23 | + enum class E : T; |
| 24 | + static constexpr T f(char) { return 1; }; |
| 25 | + enum class E : T { X = f(T{}) }; |
| 26 | +}; |
| 27 | + |
| 28 | +static_assert(static_cast<int>(S2<char>::E::X) == 1, ""); |
| 29 | + |
| 30 | +template <typename T> |
| 31 | +struct S3 { |
| 32 | + enum class E : T; |
| 33 | + enum class E : T { X = 0x7FFFFF00 }; // expected-error {{cannot be narrowed to type 'char'}} expected-warning {{implicit conversion from 'int' to 'char'}} |
| 34 | +}; |
| 35 | +template struct S3<char>; // expected-note {{in instantiation}} |
| 36 | + |
| 37 | +template <typename T> |
| 38 | +struct S4 { |
| 39 | + enum class E : T; |
| 40 | + enum class E : T { S4_X = 5 }; |
| 41 | +}; |
| 42 | + |
| 43 | +auto x4 = S4<int>::E::S4_X; |
| 44 | + |
| 45 | +template <typename T> |
| 46 | +T f1() { |
| 47 | + enum class E : T { X_F1, Y_F1, Z_F1 }; |
| 48 | + return X_F1; // expected-error {{use of undeclared identifier 'X_F1'}} |
| 49 | +} |
| 50 | + |
| 51 | +const int resf1 = f1<int>(); |
| 52 | + |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +namespace UnscopedEnumerations { |
| 57 | + |
| 58 | +template <typename T> |
| 59 | +struct S1 { |
| 60 | + enum E : T; |
| 61 | +}; |
| 62 | + |
| 63 | +template <typename T> |
| 64 | +enum S1<T>::E : T { |
| 65 | + S1_X = 0x123 |
| 66 | +}; |
| 67 | + |
| 68 | +static_assert(static_cast<int>(S1<int>::S1_X) == 0x123, ""); |
| 69 | + |
| 70 | +template <typename T> |
| 71 | +struct S2 { |
| 72 | + static constexpr T f(int) { return 0; }; |
| 73 | + enum E : T; |
| 74 | + static constexpr T f(char) { return 1; }; |
| 75 | + enum E : T { S2_X = f(T{}) }; |
| 76 | +}; |
| 77 | + |
| 78 | +static_assert(static_cast<int>(S2<char>::E::S2_X) == 1, ""); |
| 79 | + |
| 80 | +template <typename T> |
| 81 | +struct S3 { |
| 82 | + enum E : T; |
| 83 | + enum E : T { S3_X = 0x7FFFFF00 }; // expected-error {{cannot be narrowed to type 'char'}} expected-warning {{implicit conversion from 'int' to 'char'}} |
| 84 | +}; |
| 85 | +template struct S3<char>; // expected-note {{in instantiation of template class}} |
| 86 | + |
| 87 | +template <typename T> |
| 88 | +struct S4 { |
| 89 | + enum E : T; |
| 90 | + enum E : T { S4_X = 5 }; |
| 91 | +}; |
| 92 | + |
| 93 | +auto x4 = S4<int>::S4_X; |
| 94 | + |
| 95 | +template <typename T> |
| 96 | +struct S5 { |
| 97 | + enum E : T; |
| 98 | + T S5_X = 5; // expected-note {{previous definition is here}} |
| 99 | + enum E : T { S5_X = 5 }; // expected-error {{redefinition of 'S5_X'}} |
| 100 | +}; |
| 101 | + |
| 102 | + |
| 103 | +template <typename T> |
| 104 | +T f1() { |
| 105 | + enum E : T { X_F2, Y_F2, Z_F2 }; |
| 106 | + return X_F2; |
| 107 | +} |
| 108 | + |
| 109 | +const int resf1 = f1<int>(); |
| 110 | + |
| 111 | +} |
| 112 | + |
0 commit comments