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