xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/expressions.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc void test1() {
4*f4a2713aSLionel Sambuc   if (sizeof (int){ 1}) {}   // sizeof compound literal
5*f4a2713aSLionel Sambuc   if (sizeof (int)) {}       // sizeof type
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc   (void)(int)4;   // cast.
8*f4a2713aSLionel Sambuc   (void)(int){4}; // compound literal.
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc   int A = (struct{ int a;}){ 1}.a;
11*f4a2713aSLionel Sambuc }
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc int test2(int a, int b) {
14*f4a2713aSLionel Sambuc   return a ? (void)a,b : a;
15*f4a2713aSLionel Sambuc }
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc int test3(int a, int b, int c) {
18*f4a2713aSLionel Sambuc   return a = b = c;
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc int test4() {
22*f4a2713aSLionel Sambuc   test4();
23*f4a2713aSLionel Sambuc   return 0;
24*f4a2713aSLionel Sambuc }
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc struct X0 { struct { struct { int c[10][9]; } b; } a; };
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc int test_offsetof() {
29*f4a2713aSLionel Sambuc   (void)__builtin_offsetof(struct X0, a.b.c[4][5]);
30*f4a2713aSLionel Sambuc   return 0;
31*f4a2713aSLionel Sambuc }
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc void test_sizeof(){
34*f4a2713aSLionel Sambuc         int arr[10];
35*f4a2713aSLionel Sambuc         (void)sizeof arr[0];
36*f4a2713aSLionel Sambuc         (void)sizeof(arr[0]);
37*f4a2713aSLionel Sambuc         (void)sizeof(arr)[0];
38*f4a2713aSLionel Sambuc }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc // PR3418
41*f4a2713aSLionel Sambuc int test_leading_extension() {
42*f4a2713aSLionel Sambuc   __extension__ (*(char*)0) = 1; // expected-warning {{indirection of non-volatile null pointer}} \
43*f4a2713aSLionel Sambuc                                  // expected-note {{consider using __builtin_trap}}
44*f4a2713aSLionel Sambuc   return 0;
45*f4a2713aSLionel Sambuc }
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc // PR3972
48*f4a2713aSLionel Sambuc int test5(int);
49*f4a2713aSLionel Sambuc int test6(void) {
50*f4a2713aSLionel Sambuc   return test5(      // expected-note {{to match}}
51*f4a2713aSLionel Sambuc                test5(1)
52*f4a2713aSLionel Sambuc                  ; // expected-error {{expected ')'}}
53*f4a2713aSLionel Sambuc }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc // PR8394
56*f4a2713aSLionel Sambuc void test7() {
57*f4a2713aSLionel Sambuc     ({} // expected-note {{to match}}
58*f4a2713aSLionel Sambuc     ;   // expected-error {{expected ')'}}
59*f4a2713aSLionel Sambuc }
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc // PR16992
62*f4a2713aSLionel Sambuc struct pr16992 { int x; };
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc void func_16992 () {
65*f4a2713aSLionel Sambuc   int x1 = sizeof int;            // expected-error {{expected parentheses around type name in sizeof expression}}
66*f4a2713aSLionel Sambuc   int x2 = sizeof struct pr16992; // expected-error {{expected parentheses around type name in sizeof expression}}
67*f4a2713aSLionel Sambuc   int x3 = __alignof int;         // expected-error {{expected parentheses around type name in __alignof expression}}
68*f4a2713aSLionel Sambuc   int x4 = _Alignof int;          // expected-error {{expected parentheses around type name in _Alignof expression}}
69*f4a2713aSLionel Sambuc }
70