brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · e08f6e7 Raw
113 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s -verify2// RUN: %clang_cc1 -std=c++14 -fsyntax-only %s -verify3// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify4 5 6namespace ScopedEnumerations {7 8template <typename T>9struct S1 {10  enum class E : T;11};12 13template <typename T>14enum class S1<T>::E : T {15  S1_X = 0x12316};17 18static_assert(static_cast<int>(S1<int>::E::S1_X) == 0x123, "");19 20template <typename T>21struct 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 28static_assert(static_cast<int>(S2<char>::E::X) == 1, "");29 30template <typename T>31struct 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};35template struct S3<char>; // expected-note {{in instantiation}}36 37template <typename T>38struct S4 {39  enum class E : T;40  enum class E : T { S4_X = 5 };41};42 43auto x4 = S4<int>::E::S4_X;44 45template <typename T>46T 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 51const int resf1 = f1<int>();52 53}54 55 56namespace UnscopedEnumerations {57 58template <typename T>59struct S1 {60  enum E : T;61};62 63template <typename T>64enum S1<T>::E : T {65  S1_X = 0x12366};67 68static_assert(static_cast<int>(S1<int>::S1_X) == 0x123, "");69 70template <typename T>71struct 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 78static_assert(static_cast<int>(S2<char>::E::S2_X) == 1, "");79 80template <typename T>81struct 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};85template struct S3<char>; // expected-note {{in instantiation of template class}}86 87template <typename T>88struct S4 {89  enum E : T;90  enum E : T { S4_X = 5 };91};92 93auto x4 = S4<int>::S4_X;94 95template <typename T>96struct 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 103template <typename T>104T f1() {105  enum E : T { X_F2, Y_F2, Z_F2 };106  return X_F2;107}108 109const int resf1 = f1<int>();110 111}112 113