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