blob: 79dba88a9903be0949cd7b1088a02e9c5d742398 [file] [log] [blame]
Fariborz Jahanianffc120a2014-08-26 21:10:47 +00001// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
Chandler Carrutha64aedb2010-10-06 06:50:05 +00002
3
4struct A
5{
6 int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
7};
8
David Majnemer3b568aa2016-07-04 00:24:59 +00009struct PR28407
10{
11 int : 1;
12 int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
13};
14
Chandler Carrutha64aedb2010-10-06 06:50:05 +000015struct 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
24struct D {
25 int l;
26 int D[];
27};
Francois Picheta3108062010-10-18 15:01:13 +000028
Aaron Ballmandf8fe4c2013-11-24 21:35:16 +000029struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */
Francois Pichet0c71f6c2010-11-23 06:07:27 +000030
Nico Weber05e1dad2016-09-03 03:25:22 +000031[uuid("00000000-0000-0000-C000-000000000046")] struct IUnknown2 {}; /* expected-error {{'uuid' attribute is not supported in C}} */
32
Francois Pichet0c71f6c2010-11-23 06:07:27 +000033typedef struct notnested {
34 long bad1;
35 long bad2;
36} NOTNESTED;
37
38
39typedef struct nested1 {
40 long a;
41 struct notnested var1;
42 NOTNESTED var2;
43} NESTED1;
44
45struct nested2 {
46 long b;
47 NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}}
48};
49
David Majnemer36ef8982014-08-11 18:33:59 +000050struct nested2 PR20573 = { .a = 3 };
51
David Majnemer8f0ed912014-08-11 07:29:54 +000052struct 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
62typedef union nested6 {
63 long f;
64} NESTED6;
65
Francois Pichet0c71f6c2010-11-23 06:07:27 +000066struct test {
67 int c;
68 struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}}
David Majnemer8f0ed912014-08-11 07:29:54 +000069 NESTED6; // expected-warning {{anonymous unions are a Microsoft extension}}
Francois Pichet0c71f6c2010-11-23 06:07:27 +000070};
71
72void 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
Douglas Gregora1aec292011-02-22 20:32:04 +000082// Enumeration types with a fixed underlying type.
83const int seventeen = 17;
84typedef int Int;
85
86struct 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
Douglas Gregor996a735b2011-02-22 21:42:31 +000091enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
Douglas Gregora1aec292011-02-22 20:32:04 +000092 SomeValue = 0x100000000
93};
Francois Pichet6f7289d2011-05-11 22:28:19 +000094
95
96void 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;
Hans Wennborg15439bc2013-06-06 09:16:36 +0000101
102 // This is valid ISO C.
103 _Bool b = (_Bool)ptr;
Nico Weberf8bb3de2012-02-01 00:41:00 +0000104}
105
106
107typedef struct {
108 UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}}
109} AA;
110
111typedef struct {
112 AA; // expected-warning {{anonymous structs are a Microsoft extension}}
113} BB;
Aaron Ballman96e7c092012-02-23 01:19:31 +0000114
David Majnemerd8e366b2014-09-18 00:42:05 +0000115struct 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
121const int anon_falt_size = sizeof(struct anon_fault);
122
Ted Kremenekb79ee572013-12-18 23:30:06 +0000123__declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}}
124struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}}
Aaron Ballman96e7c092012-02-23 01:19:31 +0000125
126#define MY_TEXT "This is also deprecated"
Ted Kremenekb79ee572013-12-18 23:30:06 +0000127__declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}}
Aaron Ballman96e7c092012-02-23 01:19:31 +0000128
Aaron Ballman3bf758c2013-07-30 01:31:03 +0000129struct __declspec(deprecated(123)) DS2 {}; // expected-error {{'deprecated' attribute requires a string}}
Aaron Ballman478faed2012-06-19 22:09:27 +0000130
Aaron Ballman96e7c092012-02-23 01:19:31 +0000131void 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}
Aaron Ballman317a77f2013-05-22 23:25:32 +0000138
139int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
140// The modifier must follow the asterisk
141int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
142int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}}
143int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}}
144
145// It is illegal to overload based on the type attribute.
146void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}}
147void 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.
150void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}}
151void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
152
153int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
154
155__ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
156
157int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
158
159int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
160
161int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}}
162
163int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
164
165typedef int *T;
166T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
Reid Kleckner597e81d2014-03-26 15:38:33 +0000167
168typedef char *my_va_list;
Reid Kleckner55e3cec2014-03-26 22:52:23 +0000169void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}}
Reid Kleckner597e81d2014-03-26 15:38:33 +0000170void vmyprintf(const char *f, my_va_list ap);
171void myprintf(const char *f, ...) {
172 my_va_list ap;
173 if (1) {
174 __va_start(&ap, f);
175 vmyprintf(f, ap);
176 ap = 0;
177 } else {
178 __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}}
179 }
180}
Andrey Bokhanko45d41322016-05-11 18:38:21 +0000181
182// __unaligned handling
183void test_unaligned() {
184 __unaligned int *p1 = 0;
185 int *p2 = p1; // expected-warning {{initializing 'int *' with an expression of type '__unaligned int *' discards qualifiers}}
186 __unaligned int *p3 = p2;
187}
188
Andrey Bokhanko67a41862016-05-26 10:06:01 +0000189void test_unaligned2(int x[__unaligned 4]) {}
190