blob: f64012098b2567ae946fe191c16474432b3043df [file] [log] [blame]
Saleem Abdulrasool7d69c252014-07-23 01:32:32 +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
9struct C {
10 int l;
11 union {
12 int c1[]; /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}} */
13 char c2[]; /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */
14 };
15};
16
17
18struct D {
19 int l;
20 int D[];
21};
Francois Picheta3108062010-10-18 15:01:13 +000022
Aaron Ballmandf8fe4c2013-11-24 21:35:16 +000023struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */
Francois Pichet0c71f6c2010-11-23 06:07:27 +000024
25typedef struct notnested {
26 long bad1;
27 long bad2;
28} NOTNESTED;
29
30
31typedef struct nested1 {
32 long a;
33 struct notnested var1;
34 NOTNESTED var2;
35} NESTED1;
36
37struct nested2 {
38 long b;
39 NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}}
40};
41
David Majnemer8f0ed912014-08-11 07:29:54 +000042struct nested3 {
43 long d;
44 struct nested4 { // expected-warning {{anonymous structs are a Microsoft extension}}
45 long e;
46 };
47 union nested5 { // expected-warning {{anonymous unions are a Microsoft extension}}
48 long f;
49 };
50};
51
52typedef union nested6 {
53 long f;
54} NESTED6;
55
Francois Pichet0c71f6c2010-11-23 06:07:27 +000056struct test {
57 int c;
58 struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}}
David Majnemer8f0ed912014-08-11 07:29:54 +000059 NESTED6; // expected-warning {{anonymous unions are a Microsoft extension}}
Francois Pichet0c71f6c2010-11-23 06:07:27 +000060};
61
62void foo()
63{
64 struct test var;
65 var.a;
66 var.b;
67 var.c;
68 var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}}
69 var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}}
70}
71
Douglas Gregora1aec292011-02-22 20:32:04 +000072// Enumeration types with a fixed underlying type.
73const int seventeen = 17;
74typedef int Int;
75
76struct X0 {
77 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
78 enum E1 : seventeen;
79};
80
Douglas Gregor996a735b2011-02-22 21:42:31 +000081enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
Douglas Gregora1aec292011-02-22 20:32:04 +000082 SomeValue = 0x100000000
83};
Francois Pichet6f7289d2011-05-11 22:28:19 +000084
85
86void pointer_to_integral_type_conv(char* ptr) {
87 char ch = (char)ptr;
88 short sh = (short)ptr;
89 ch = (char)ptr;
90 sh = (short)ptr;
Hans Wennborg15439bc2013-06-06 09:16:36 +000091
92 // This is valid ISO C.
93 _Bool b = (_Bool)ptr;
Nico Weberf8bb3de2012-02-01 00:41:00 +000094}
95
96
97typedef struct {
98 UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}}
99} AA;
100
101typedef struct {
102 AA; // expected-warning {{anonymous structs are a Microsoft extension}}
103} BB;
Aaron Ballman96e7c092012-02-23 01:19:31 +0000104
Ted Kremenekb79ee572013-12-18 23:30:06 +0000105__declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}}
106struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}}
Aaron Ballman96e7c092012-02-23 01:19:31 +0000107
108#define MY_TEXT "This is also deprecated"
Ted Kremenekb79ee572013-12-18 23:30:06 +0000109__declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}}
Aaron Ballman96e7c092012-02-23 01:19:31 +0000110
Aaron Ballman3bf758c2013-07-30 01:31:03 +0000111struct __declspec(deprecated(123)) DS2 {}; // expected-error {{'deprecated' attribute requires a string}}
Aaron Ballman478faed2012-06-19 22:09:27 +0000112
Aaron Ballman96e7c092012-02-23 01:19:31 +0000113void test( void ) {
114 e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}}
115 struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}}
116 Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}}
117
118 enum DE1 no; // no warning because E1 is not deprecated
119}
Aaron Ballman317a77f2013-05-22 23:25:32 +0000120
121int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
122// The modifier must follow the asterisk
123int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
124int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}}
125int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}}
126
127// It is illegal to overload based on the type attribute.
128void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}}
129void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}}
130
131// It is also illegal to overload based on the pointer type attribute.
132void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}}
133void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
134
135int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
136
137__ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
138
139int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
140
141int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
142
143int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}}
144
145int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
146
147typedef int *T;
148T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
Reid Kleckner597e81d2014-03-26 15:38:33 +0000149
150typedef char *my_va_list;
Reid Kleckner55e3cec2014-03-26 22:52:23 +0000151void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}}
Reid Kleckner597e81d2014-03-26 15:38:33 +0000152void vmyprintf(const char *f, my_va_list ap);
153void myprintf(const char *f, ...) {
154 my_va_list ap;
155 if (1) {
156 __va_start(&ap, f);
157 vmyprintf(f, ap);
158 ap = 0;
159 } else {
160 __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}}
161 }
162}