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