enums.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #pragma once
  2. // Sample file for parse_enum unittests
  3. #include <util/generic/fwd.h>
  4. #include <util/system/compiler.h>
  5. // Test template declarations
  6. template<class T>
  7. void Func(T&);
  8. template<>
  9. void Func(struct ENonDeclared&);
  10. template<class TClass> class TFwdDecl;
  11. // Test in-function class declarations
  12. void InexistentFunction(struct TFwdStructDecl);
  13. void InexistentFunction2(struct TFwdStructDecl, class TMegaClass);
  14. static inline void Func() {
  15. class TLocal {
  16. int M;
  17. public:
  18. void F() {
  19. // to shut up clang
  20. Y_UNUSED(M);
  21. }
  22. };
  23. {
  24. // unnamed block
  25. }
  26. }
  27. // Test forward declarations, pt 2
  28. namespace NTestContainer {
  29. struct TStruct;
  30. }
  31. // Enums
  32. enum ESimple {
  33. Http,
  34. Https,
  35. ItemCount
  36. };
  37. enum class ESimpleWithComma {
  38. Http = 3,
  39. Http2 = Http,
  40. Https, // 4
  41. ItemCount, // 5
  42. };
  43. enum ECustomAliases {
  44. CAHttp = 3 /* "http" */,
  45. CAHttps /* "https" */,
  46. CAItemCount,
  47. };
  48. enum EMultipleAliases {
  49. MAHttp = 9 /* "http://" "secondary" "old\nvalue" */,
  50. MAHttps = 1 /* "https://" */,
  51. MAItemCount,
  52. };
  53. namespace NEnumNamespace {
  54. enum EInNamespace {
  55. Http = 9 /* "http://" "secondary" "old\nvalue" */,
  56. Https = 1 /* "https://" */,
  57. ItemCount /* "real value" */,
  58. };
  59. };
  60. struct TStruct {
  61. int M;
  62. };
  63. namespace NEnumNamespace {
  64. class TEnumClass: public TStruct {
  65. public:
  66. enum EInClass {
  67. Http = 9 /* "http://" "secondary" "old\nvalue" */,
  68. Https1 = NEnumNamespace::Https /* "https://" */,
  69. // holy crap, this will work too:
  70. Https3 = 1 /* "https://" */ + 2,
  71. };
  72. };
  73. }
  74. enum {
  75. One,
  76. Two,
  77. Three,
  78. };
  79. struct {
  80. int M;
  81. } SomeStruct;
  82. static inline void f() {
  83. (void)(SomeStruct);
  84. (void)(f);
  85. }
  86. // buggy case taken from library/cpp/html/face/parstypes.h
  87. enum TEXT_WEIGHT {
  88. WEIGHT_ZERO=-1,// NOINDEX_RELEV
  89. WEIGHT_LOW, // LOW_RELEV
  90. WEIGHT_NORMAL, // NORMAL_RELEV
  91. WEIGHT_HIGH, // HIGH_RELEV (H1,H2,H3,ADDRESS,CAPTION)
  92. WEIGHT_BEST // BEST_RELEV (TITLE)
  93. };
  94. // enum with duplicate keys
  95. enum EDuplicateKeys {
  96. Key0 = 0,
  97. Key0Second = Key0,
  98. Key1,
  99. Key2 = 3 /* "k2" "k2.1" */,
  100. Key3 = 3 /* "k3" */,
  101. };
  102. enum class EFwdEnum;
  103. void FunctionUsingEFwdEnum(EFwdEnum);
  104. enum class EFwdEnum {
  105. One,
  106. Two
  107. };
  108. // empty enum (bug found by sankear@)
  109. enum EEmpty {
  110. };
  111. namespace NComposite::NInner {
  112. enum EInCompositeNamespaceSimple {
  113. one,
  114. two = 2,
  115. three,
  116. };
  117. }
  118. namespace NOuterSimple {
  119. namespace NComposite::NMiddle::NInner {
  120. namespace NInnerSimple {
  121. class TEnumClass {
  122. public:
  123. enum EVeryDeep {
  124. Key0 = 0,
  125. Key1 = 1,
  126. };
  127. };
  128. }
  129. }
  130. }
  131. constexpr int func(int value) {
  132. return value;
  133. }
  134. #define MACRO(x, y) x
  135. // enum with nonliteral values
  136. enum ENonLiteralValues {
  137. one = MACRO(1, 2),
  138. two = 2,
  139. three = func(3),
  140. four,
  141. five = MACRO(MACRO(1, 2), 2),
  142. };
  143. #undef MACRO
  144. enum EDestructionPriorityTest {
  145. first,
  146. second
  147. };
  148. enum class NotifyingStatus
  149. {
  150. NEW = 0,
  151. FAILED_WILL_RETRY = 1,
  152. FAILED_NO_MORE_TRIALS = 2,
  153. SENT = 3
  154. };
  155. /*
  156. * Still unsupported features:
  157. *
  158. * a) Anonymous namespaces (it is parsed correctly, though)
  159. * b) Enums inside template classes (impossible by design)
  160. **/