[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / empty1.c
blob6c5fe76833f3f623a666d42584e07d0b450a97d1
1 // RUN: %clang_cc1 %s -triple %itanium_abi_triple -fsyntax-only -verify -Wc++-compat
3 // Note: Empty C structs are 4 bytes in the Microsoft ABI.
5 struct emp_1 { // expected-warning {{empty struct has size 0 in C, size 1 in C++}}
6 };
8 union emp_2 { // expected-warning {{empty union has size 0 in C, size 1 in C++}}
9 };
11 struct emp_3 { // expected-warning {{struct has size 0 in C, size 1 in C++}}
12 int : 0;
15 union emp_4 { // expected-warning {{union has size 0 in C, size 1 in C++}}
16 int : 0;
19 struct emp_5 { // expected-warning {{struct has size 0 in C, size 1 in C++}}
20 int : 0;
21 int : 0;
24 union emp_6 { // expected-warning {{union has size 0 in C, size 1 in C++}}
25 int : 0;
26 int : 0;
29 struct emp_7 { // expected-warning {{struct has size 0 in C, size 1 in C++}}
30 struct emp_1 f1;
33 union emp_8 { // expected-warning {{union has size 0 in C, size 1 in C++}}
34 struct emp_1 f1;
37 struct emp_9 { // expected-warning {{struct has size 0 in C, non-zero size in C++}}
38 struct emp_1 f1;
39 union emp_2 f2;
42 // Checks for pointer subtraction (PR15683)
43 struct emp_1 *func_1p(struct emp_1 *x) { return x - 5; }
45 int func_1(void) {
46 struct emp_1 v[1];
47 return v - v; // expected-warning {{subtraction of pointers to type 'struct emp_1' of zero size has undefined behavior}}
50 int func_2(struct emp_1 *x) {
51 return 1 + x - x; // expected-warning {{subtraction of pointers to type 'struct emp_1' of zero size has undefined behavior}}
54 int func_3(struct emp_1 *x, struct emp_1 *y) {
55 return x - y; // expected-warning {{subtraction of pointers to type 'struct emp_1' of zero size has undefined behavior}}
58 int func_4(struct emp_1 *x, const struct emp_1 *y) {
59 return x - y; // expected-warning {{subtraction of pointers to type 'struct emp_1' of zero size has undefined behavior}}
62 int func_5(volatile struct emp_1 *x, const struct emp_1 *y) {
63 return x - y; // expected-warning {{subtraction of pointers to type 'struct emp_1' of zero size has undefined behavior}}
66 int func_6(void) {
67 union emp_2 v[1];
68 return v - v; // expected-warning {{subtraction of pointers to type 'union emp_2' of zero size has undefined behavior}}
71 struct A; // expected-note {{forward declaration of 'struct A'}}
73 int func_7(struct A *x, struct A *y) {
74 return x - y; // expected-error {{arithmetic on a pointer to an incomplete type 'struct A'}}
77 int func_8(struct emp_1 (*x)[10], struct emp_1 (*y)[10]) {
78 return x - y; // expected-warning {{subtraction of pointers to type 'struct emp_1[10]' of zero size has undefined behavior}}
81 int func_9(struct emp_1 (*x)[], struct emp_1 (*y)[]) {
82 return x - y; // expected-error {{arithmetic on a pointer to an incomplete type 'struct emp_1[]'}}
85 int func_10(int (*x)[0], int (*y)[0]) {
86 return x - y; // expected-warning {{subtraction of pointers to type 'int[0]' of zero size has undefined behavior}}