xref: /aosp_15_r20/external/clang/test/Sema/pointer-addition.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -std=c11
2*67e74705SXin Li 
3*67e74705SXin Li typedef struct S S; // expected-note 4 {{forward declaration of 'struct S'}}
4*67e74705SXin Li extern _Atomic(S*) e;
a(S * b,void * c)5*67e74705SXin Li void a(S* b, void* c) {
6*67e74705SXin Li   void (*fp)(int) = 0;
7*67e74705SXin Li   b++;       // expected-error {{arithmetic on a pointer to an incomplete type}}
8*67e74705SXin Li   b += 1;    // expected-error {{arithmetic on a pointer to an incomplete type}}
9*67e74705SXin Li   c++;       // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
10*67e74705SXin Li   c += 1;    // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
11*67e74705SXin Li   c--;       // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
12*67e74705SXin Li   c -= 1;    // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
13*67e74705SXin Li   (void) c[1]; // expected-warning {{subscript of a pointer to void is a GNU extension}}
14*67e74705SXin Li   b = 1+b;   // expected-error {{arithmetic on a pointer to an incomplete type}}
15*67e74705SXin Li   /* The next couple tests are only pedantic warnings in gcc */
16*67e74705SXin Li   void (*d)(S*,void*) = a;
17*67e74705SXin Li   d += 1;    // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' (aka 'void (struct S *, void *)') is a GNU extension}}
18*67e74705SXin Li   d++;       // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' (aka 'void (struct S *, void *)') is a GNU extension}}
19*67e74705SXin Li   d--;       // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' (aka 'void (struct S *, void *)') is a GNU extension}}
20*67e74705SXin Li   d -= 1;    // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' (aka 'void (struct S *, void *)') is a GNU extension}}
21*67e74705SXin Li   (void)(1 + d); // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' (aka 'void (struct S *, void *)') is a GNU extension}}
22*67e74705SXin Li   e++;       // expected-error {{arithmetic on a pointer to an incomplete type}}
23*67e74705SXin Li }
24