1 // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
2 
3 
4 struct A
5 {
6    int a[];  /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
7 };
8 
9 struct PR28407
10 {
11   int : 1;
12   int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
13 };
14 
15 struct C {
16    int l;
17    union {
18        int c1[];   /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}}  */
19        char c2[];  /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */
20    };
21 };
22 
23 
24 struct D {
25    int l;
26    int D[];
27 };
28 
29 struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */
30 
31 [uuid("00000000-0000-0000-C000-000000000046")] struct IUnknown2 {}; /* expected-error {{'uuid' attribute is not supported in C}} */
32 
33 typedef struct notnested {
34   long bad1;
35   long bad2;
36 } NOTNESTED;
37 
38 
39 typedef struct nested1 {
40   long a;
41   struct notnested var1;
42   NOTNESTED var2;
43 } NESTED1;
44 
45 struct nested2 {
46   long b;
47   NESTED1;  // expected-warning {{anonymous structs are a Microsoft extension}}
48 };
49 
50 struct nested2 PR20573 = { .a = 3 };
51 
52 struct nested3 {
53   long d;
54   struct nested4 { // expected-warning {{anonymous structs are a Microsoft extension}}
55     long e;
56   };
57   union nested5 { // expected-warning {{anonymous unions are a Microsoft extension}}
58     long f;
59   };
60 };
61 
62 typedef union nested6 {
63   long f;
64 } NESTED6;
65 
66 struct test {
67   int c;
68   struct nested2;   // expected-warning {{anonymous structs are a Microsoft extension}}
69   NESTED6;   // expected-warning {{anonymous unions are a Microsoft extension}}
70 };
71 
foo()72 void foo()
73 {
74   struct test var;
75   var.a;
76   var.b;
77   var.c;
78   var.bad1;   // expected-error {{no member named 'bad1' in 'struct test'}}
79   var.bad2;   // expected-error {{no member named 'bad2' in 'struct test'}}
80 }
81 
82 // Enumeration types with a fixed underlying type.
83 const int seventeen = 17;
84 typedef int Int;
85 
86 struct X0 {
87   enum E1 : Int { SomeOtherValue } field;  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
88   enum E1 : seventeen;
89 };
90 
91 enum : long long {  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
92   SomeValue = 0x100000000
93 };
94 
95 
pointer_to_integral_type_conv(char * ptr)96 void pointer_to_integral_type_conv(char* ptr) {
97    char ch = (char)ptr;
98    short sh = (short)ptr;
99    ch = (char)ptr;
100    sh = (short)ptr;
101 
102    // This is valid ISO C.
103    _Bool b = (_Bool)ptr;
104 }
105 
106 
107 typedef struct {
108   UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}}
109 } AA;
110 
111 typedef struct {
112   AA; // expected-warning {{anonymous structs are a Microsoft extension}}
113 } BB;
114 
115 struct anon_fault {
116   struct undefined; // expected-warning {{anonymous structs are a Microsoft extension}}
117                     // expected-error@-1 {{field has incomplete type 'struct undefined'}}
118                     // expected-note@-2 {{forward declaration of 'struct undefined'}}
119 };
120 
121 const int anon_falt_size = sizeof(struct anon_fault);
122 
123 __declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}}
124 struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}}
125 
126 #define MY_TEXT		"This is also deprecated"
deprecated(MY_TEXT)127 __declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}}
128 
129 struct __declspec(deprecated(123)) DS2 {};	// expected-error {{'deprecated' attribute requires a string}}
130 
test(void)131 void test( void ) {
132 	e1 = one;	// expected-warning {{'e1' is deprecated: This is deprecated}}
133 	struct DS1 s = { 0 };	// expected-warning {{'DS1' is deprecated}}
134 	Dfunc1();	// expected-warning {{'Dfunc1' is deprecated: This is also deprecated}}
135 
136 	enum DE1 no;	// no warning because E1 is not deprecated
137 }
138 
139 int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
140 // The modifier must follow the asterisk
141 int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
142 int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}}
143 int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}}
144 
145 // It is illegal to overload based on the type attribute.
ptr_func(int * __ptr32 i)146 void ptr_func(int * __ptr32 i) {}  // expected-note {{previous definition is here}}
ptr_func(int * __ptr64 i)147 void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}}
148 
149 // It is also illegal to overload based on the pointer type attribute.
ptr_func2(int * __sptr __ptr32 i)150 void ptr_func2(int * __sptr __ptr32 i) {}  // expected-note {{previous definition is here}}
ptr_func2(int * __uptr __ptr32 i)151 void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
152 
153 // Check for warning when return types have the type attribute.
ptr_func3()154 void *__ptr32 ptr_func3() { return 0; } // expected-note {{previous definition is here}}
ptr_func3()155 void *__ptr64 ptr_func3() { return 0; } // expected-error {{redefinition of 'ptr_func3'}}
156 
157 // Test that __ptr32/__ptr64 can be passed as arguments with other address
158 // spaces.
159 void ptr_func4(int *i);
160 void ptr_func5(int *__ptr32 i);
test_ptr_arguments()161 void test_ptr_arguments() {
162   int *__ptr64 i64;
163   ptr_func4(i64);
164   ptr_func5(i64);
165 }
166 
167 int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
168 
169 __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
170 
171 int *wrong6 __ptr32;  // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
172 
173 int * __ptr32 __ptr64 wrong7;  // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
174 
175 int * __ptr32 __ptr32 wrong8;	// expected-warning {{attribute '__ptr32' is already applied}}
176 
177 int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
178 
179 typedef int *T;
180 T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
181 
182 typedef char *my_va_list;
183 void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}}
184 void vmyprintf(const char *f, my_va_list ap);
myprintf(const char * f,...)185 void myprintf(const char *f, ...) {
186   my_va_list ap;
187   if (1) {
188     __va_start(&ap, f);
189     vmyprintf(f, ap);
190     ap = 0;
191   } else {
192     __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}}
193   }
194 }
195 
196 // __unaligned handling
test_unaligned()197 void test_unaligned() {
198   __unaligned int *p1 = 0;
199   int *p2 = p1; // expected-warning {{initializing 'int *' with an expression of type '__unaligned int *' discards qualifiers}}
200   __unaligned int *p3 = p2;
201 }
202 
test_unaligned2(int x[__unaligned4])203 void test_unaligned2(int x[__unaligned 4]) {}
204 
205