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 typedef struct notnested { 32 long bad1; 33 long bad2; 34 } NOTNESTED; 35 36 37 typedef struct nested1 { 38 long a; 39 struct notnested var1; 40 NOTNESTED var2; 41 } NESTED1; 42 43 struct nested2 { 44 long b; 45 NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}} 46 }; 47 48 struct nested2 PR20573 = { .a = 3 }; 49 50 struct nested3 { 51 long d; 52 struct nested4 { // expected-warning {{anonymous structs are a Microsoft extension}} 53 long e; 54 }; 55 union nested5 { // expected-warning {{anonymous unions are a Microsoft extension}} 56 long f; 57 }; 58 }; 59 60 typedef union nested6 { 61 long f; 62 } NESTED6; 63 64 struct test { 65 int c; 66 struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}} 67 NESTED6; // expected-warning {{anonymous unions are a Microsoft extension}} 68 }; 69 foo()70void foo() 71 { 72 struct test var; 73 var.a; 74 var.b; 75 var.c; 76 var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}} 77 var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}} 78 } 79 80 // Enumeration types with a fixed underlying type. 81 const int seventeen = 17; 82 typedef int Int; 83 84 struct X0 { 85 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} 86 enum E1 : seventeen; 87 }; 88 89 enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} 90 SomeValue = 0x100000000 91 }; 92 93 pointer_to_integral_type_conv(char * ptr)94void pointer_to_integral_type_conv(char* ptr) { 95 char ch = (char)ptr; 96 short sh = (short)ptr; 97 ch = (char)ptr; 98 sh = (short)ptr; 99 100 // This is valid ISO C. 101 _Bool b = (_Bool)ptr; 102 } 103 104 105 typedef struct { 106 UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}} 107 } AA; 108 109 typedef struct { 110 AA; // expected-warning {{anonymous structs are a Microsoft extension}} 111 } BB; 112 113 struct anon_fault { 114 struct undefined; // expected-warning {{anonymous structs are a Microsoft extension}} 115 // expected-error@-1 {{field has incomplete type 'struct undefined'}} 116 // expected-note@-2 {{forward declaration of 'struct undefined'}} 117 }; 118 119 const int anon_falt_size = sizeof(struct anon_fault); 120 121 __declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}} 122 struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}} 123 124 #define MY_TEXT "This is also deprecated" Dfunc1(void)125__declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}} 126 127 struct __declspec(deprecated(123)) DS2 {}; // expected-error {{'deprecated' attribute requires a string}} 128 test(void)129void test( void ) { 130 e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}} 131 struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}} 132 Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}} 133 134 enum DE1 no; // no warning because E1 is not deprecated 135 } 136 137 int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}} 138 // The modifier must follow the asterisk 139 int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}} 140 int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}} 141 int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}} 142 143 // It is illegal to overload based on the type attribute. ptr_func(int * __ptr32 i)144void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}} ptr_func(int * __ptr64 i)145void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}} 146 147 // It is also illegal to overload based on the pointer type attribute. ptr_func2(int * __sptr __ptr32 i)148void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}} ptr_func2(int * __uptr __ptr32 i)149void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}} 150 151 int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}} 152 153 __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} 154 155 int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}} 156 157 int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}} 158 159 int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}} 160 161 int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}} 162 163 typedef int *T; 164 T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} 165 166 typedef char *my_va_list; 167 void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}} 168 void vmyprintf(const char *f, my_va_list ap); myprintf(const char * f,...)169void myprintf(const char *f, ...) { 170 my_va_list ap; 171 if (1) { 172 __va_start(&ap, f); 173 vmyprintf(f, ap); 174 ap = 0; 175 } else { 176 __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}} 177 } 178 } 179 180 // __unaligned handling test_unaligned()181void test_unaligned() { 182 __unaligned int *p1 = 0; 183 int *p2 = p1; // expected-warning {{initializing 'int *' with an expression of type '__unaligned int *' discards qualifiers}} 184 __unaligned int *p3 = p2; 185 } 186 test_unaligned2(int x[__unaligned4])187void test_unaligned2(int x[__unaligned 4]) {} 188 189