| 1 | #include <limits> |
| 2 | |
| 3 | enum Enum { |
| 4 | enum_case1 = 1, |
| 5 | enum_case2 = 2, |
| 6 | }; |
| 7 | |
| 8 | enum EnumBool : bool { |
| 9 | enum_bool_case1 = false, |
| 10 | enum_bool_case2 = true, |
| 11 | }; |
| 12 | |
| 13 | enum class ScopedEnum { |
| 14 | scoped_enum_case1 = 1, |
| 15 | scoped_enum_case2 = 2, |
| 16 | }; |
| 17 | |
| 18 | enum class ScopedCharEnum : char { |
| 19 | case1 = 1, |
| 20 | case2 = 2, |
| 21 | }; |
| 22 | |
| 23 | enum class ScopedLongLongEnum : long long { |
| 24 | case0 = std::numeric_limits<long long>::min(), |
| 25 | case1 = 1, |
| 26 | case2 = std::numeric_limits<long long>::max(), |
| 27 | }; |
| 28 | |
| 29 | struct A { |
| 30 | const static int int_val = 1; |
| 31 | const static int int_val_with_address = 2; |
| 32 | inline const static int inline_int_val = 3; |
| 33 | const static bool bool_val = true; |
| 34 | |
| 35 | const static auto char_max = std::numeric_limits<char>::max(); |
| 36 | const static auto schar_max = std::numeric_limits<signed char>::max(); |
| 37 | const static auto uchar_max = std::numeric_limits<unsigned char>::max(); |
| 38 | const static auto int_max = std::numeric_limits<int>::max(); |
| 39 | const static auto uint_max = std::numeric_limits<unsigned>::max(); |
| 40 | const static auto long_max = std::numeric_limits<long>::max(); |
| 41 | const static auto ulong_max = std::numeric_limits<unsigned long>::max(); |
| 42 | const static auto longlong_max = std::numeric_limits<long long>::max(); |
| 43 | const static auto ulonglong_max = |
| 44 | std::numeric_limits<unsigned long long>::max(); |
| 45 | const static auto wchar_max = std::numeric_limits<wchar_t>::max(); |
| 46 | |
| 47 | const static auto char_min = std::numeric_limits<char>::min(); |
| 48 | const static auto schar_min = std::numeric_limits<signed char>::min(); |
| 49 | const static auto uchar_min = std::numeric_limits<unsigned char>::min(); |
| 50 | const static auto int_min = std::numeric_limits<int>::min(); |
| 51 | const static auto uint_min = std::numeric_limits<unsigned>::min(); |
| 52 | const static auto long_min = std::numeric_limits<long>::min(); |
| 53 | const static auto ulong_min = std::numeric_limits<unsigned long>::min(); |
| 54 | const static auto longlong_min = std::numeric_limits<long long>::min(); |
| 55 | const static auto ulonglong_min = |
| 56 | std::numeric_limits<unsigned long long>::min(); |
| 57 | const static auto wchar_min = std::numeric_limits<wchar_t>::min(); |
| 58 | |
| 59 | const static Enum enum_val = enum_case2; |
| 60 | const static EnumBool enum_bool_val = enum_bool_case1; |
| 61 | const static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2; |
| 62 | const static ScopedEnum not_enumerator_scoped_enum_val = static_cast<ScopedEnum>(5); |
| 63 | const static ScopedEnum not_enumerator_scoped_enum_val_2 = |
| 64 | static_cast<ScopedEnum>(7); |
| 65 | const static ScopedCharEnum scoped_char_enum_val = ScopedCharEnum::case2; |
| 66 | const static ScopedLongLongEnum scoped_ll_enum_val_neg = |
| 67 | ScopedLongLongEnum::case0; |
| 68 | const static ScopedLongLongEnum scoped_ll_enum_val = |
| 69 | ScopedLongLongEnum::case2; |
| 70 | }; |
| 71 | |
| 72 | const int A::int_val_with_address; |
| 73 | |
| 74 | struct ClassWithOnlyConstStatic { |
| 75 | const static int member = 3; |
| 76 | }; |
| 77 | |
| 78 | struct ClassWithConstexprs { |
| 79 | constexpr static int member = 2; |
| 80 | constexpr static Enum enum_val = enum_case2; |
| 81 | constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2; |
| 82 | } cwc; |
| 83 | |
| 84 | struct ClassWithEnumAlias { |
| 85 | using EnumAlias = ScopedEnum; |
| 86 | static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2; |
| 87 | |
| 88 | using EnumAliasAlias = EnumAlias; |
| 89 | static constexpr EnumAliasAlias enum_alias_alias = |
| 90 | ScopedEnum::scoped_enum_case1; |
| 91 | }; |
| 92 | |
| 93 | namespace ns { |
| 94 | struct Foo { |
| 95 | constexpr static int mem = 10; |
| 96 | |
| 97 | void bar() { return; } |
| 98 | }; |
| 99 | } // namespace ns |
| 100 | |
| 101 | struct Foo { |
| 102 | constexpr static int mem = -29; |
| 103 | }; |
| 104 | |
| 105 | int func() { |
| 106 | Foo f1; |
| 107 | ns::Foo f2; |
| 108 | f2.bar(); |
| 109 | return ns::Foo::mem + Foo::mem; |
| 110 | } |
| 111 | |
| 112 | int main() { |
| 113 | A a; |
| 114 | |
| 115 | auto char_max = A::char_max; |
| 116 | auto schar_max = A::schar_max; |
| 117 | auto uchar_max = A::uchar_max; |
| 118 | auto int_max = A::int_max; |
| 119 | auto uint_max = A::uint_max; |
| 120 | auto long_max = A::long_max; |
| 121 | auto ulong_max = A::ulong_max; |
| 122 | auto longlong_max = A::longlong_max; |
| 123 | auto ulonglong_max = A::ulonglong_max; |
| 124 | auto wchar_max = A::wchar_max; |
| 125 | |
| 126 | auto char_min = A::char_min; |
| 127 | auto schar_min = A::schar_min; |
| 128 | auto uchar_min = A::uchar_min; |
| 129 | auto int_min = A::int_min; |
| 130 | auto uint_min = A::uint_min; |
| 131 | auto long_min = A::long_min; |
| 132 | auto ulong_min = A::ulong_min; |
| 133 | auto longlong_min = A::longlong_min; |
| 134 | auto ulonglong_min = A::ulonglong_min; |
| 135 | auto wchar_min = A::wchar_min; |
| 136 | |
| 137 | int member_copy = ClassWithOnlyConstStatic::member; |
| 138 | |
| 139 | Enum e = A::enum_val; |
| 140 | ScopedEnum se = A::scoped_enum_val; |
| 141 | se = A::not_enumerator_scoped_enum_val; |
| 142 | ScopedCharEnum sce = A::scoped_char_enum_val; |
| 143 | ScopedLongLongEnum sle = A::scoped_ll_enum_val; |
| 144 | |
| 145 | auto enum_alias_val = ClassWithEnumAlias::enum_alias; |
| 146 | auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias; |
| 147 | auto ret = func(); |
| 148 | |
| 149 | return 0; // break here |
| 150 | } |
| 151 | |