Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1 | // Integer literals |
| 2 | const char Ch1 = 'a'; |
| 3 | const signed char Ch2 = 'b'; |
| 4 | const unsigned char Ch3 = 'c'; |
| 5 | |
| 6 | const wchar_t Ch4 = L'd'; |
| 7 | const signed wchar_t Ch5 = L'e'; |
| 8 | const unsigned wchar_t Ch6 = L'f'; |
| 9 | |
| 10 | const short C1 = 12; |
| 11 | const unsigned short C2 = 13; |
| 12 | |
| 13 | const int C3 = 12; |
| 14 | const unsigned int C4 = 13; |
| 15 | |
| 16 | const long C5 = 22; |
| 17 | const unsigned long C6 = 23; |
| 18 | |
| 19 | const long long C7 = 66; |
| 20 | const unsigned long long C8 = 67; |
| 21 | |
| 22 | |
| 23 | // String literals |
| 24 | const char str1[] = "ABCD"; |
| 25 | const char str2[] = "ABCD" "0123"; |
| 26 | |
| 27 | const wchar_t wstr1[] = L"DEF"; |
| 28 | const wchar_t wstr2[] = L"DEF" L"123"; |
| 29 | |
| 30 | |
| 31 | // Boolean literals |
| 32 | const bool bval1 = true; |
| 33 | const bool bval2 = false; |
| 34 | |
| 35 | // Floating Literals |
| 36 | const float F1 = 12.2F; |
| 37 | const double F2 = 1E4; |
| 38 | const long double F3 = 1.2E-3L; |
| 39 | |
| 40 | |
| 41 | // nullptr literal |
| 42 | const void *vptr = nullptr; |
| 43 | |
| 44 | |
| 45 | int glb_1[4] = { 10, 20, 30, 40 }; |
| 46 | |
| 47 | struct S1 { |
| 48 | int a; |
| 49 | int b[3]; |
| 50 | }; |
| 51 | |
| 52 | struct S2 { |
| 53 | int c; |
| 54 | S1 d; |
| 55 | }; |
| 56 | |
| 57 | S2 glb_2 = { 22, .d.a = 44, .d.b[0] = 55, .d.b[1] = 66 }; |
| 58 | |
| 59 | void testNewThrowDelete() { |
| 60 | throw; |
| 61 | char *p = new char[10]; |
| 62 | delete[] p; |
| 63 | } |
| 64 | |
| 65 | int testArrayElement(int *x, int n) { |
| 66 | return x[n]; |
| 67 | } |
| 68 | |
| 69 | int testTernaryOp(int c, int x, int y) { |
| 70 | return c ? x : y; |
| 71 | } |
| 72 | |
| 73 | S1 &testConstCast(const S1 &x) { |
| 74 | return const_cast<S1&>(x); |
| 75 | } |
| 76 | |
| 77 | S1 &testStaticCast(S1 &x) { |
| 78 | return static_cast<S1&>(x); |
| 79 | } |
| 80 | |
| 81 | S1 &testReinterpretCast(S1 &x) { |
| 82 | return reinterpret_cast<S1&>(x); |
| 83 | } |
| 84 | |
| 85 | S1 &testDynamicCast(S1 &x) { |
| 86 | return dynamic_cast<S1&>(x); |
| 87 | } |
| 88 | |
| 89 | int testScalarInit(int x) { |
| 90 | return int(x); |
| 91 | } |
| 92 | |
| 93 | struct S { |
| 94 | float f; |
| 95 | double d; |
| 96 | }; |
| 97 | struct T { |
| 98 | int i; |
| 99 | struct S s[10]; |
| 100 | }; |
| 101 | |
| 102 | void testOffsetOf() { |
| 103 | __builtin_offsetof(struct T, s[2].d); |
| 104 | } |
| 105 | |
| 106 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 107 | int testDefaultArg(int a = 2*2) { |
| 108 | return a; |
| 109 | } |
| 110 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame^] | 111 | int testDefaultArgExpr() { |
| 112 | return testDefaultArg(); |
| 113 | } |
| 114 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 115 | template <typename T> // T has TemplateTypeParmType |
| 116 | void testTemplateTypeParmType(int i); |
| 117 | |
| 118 | void useTemplateType() { |
| 119 | testTemplateTypeParmType<char>(4); |
| 120 | } |
| 121 | |
| 122 | const bool ExpressionTrait = __is_lvalue_expr(1); |
| 123 | const unsigned ArrayRank = __array_rank(int[10][20]); |
| 124 | const unsigned ArrayExtent = __array_extent(int[10][20], 1); |