Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions |
Chandler Carruth | b644894 | 2010-10-06 06:50:05 +0000 | [diff] [blame] | 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 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 | |
| 18 | struct D { |
| 19 | int l; |
| 20 | int D[]; |
| 21 | }; |
Francois Pichet | 842e7a2 | 2010-10-18 15:01:13 +0000 | [diff] [blame] | 22 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 23 | struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */ |
Francois Pichet | 8e161ed | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 24 | |
| 25 | typedef struct notnested { |
| 26 | long bad1; |
| 27 | long bad2; |
| 28 | } NOTNESTED; |
| 29 | |
| 30 | |
| 31 | typedef struct nested1 { |
| 32 | long a; |
| 33 | struct notnested var1; |
| 34 | NOTNESTED var2; |
| 35 | } NESTED1; |
| 36 | |
| 37 | struct nested2 { |
| 38 | long b; |
| 39 | NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 40 | }; |
| 41 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 42 | struct nested2 PR20573 = { .a = 3 }; |
| 43 | |
| 44 | struct nested3 { |
| 45 | long d; |
| 46 | struct nested4 { // expected-warning {{anonymous structs are a Microsoft extension}} |
| 47 | long e; |
| 48 | }; |
| 49 | union nested5 { // expected-warning {{anonymous unions are a Microsoft extension}} |
| 50 | long f; |
| 51 | }; |
| 52 | }; |
| 53 | |
| 54 | typedef union nested6 { |
| 55 | long f; |
| 56 | } NESTED6; |
| 57 | |
Francois Pichet | 8e161ed | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 58 | struct test { |
| 59 | int c; |
| 60 | struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}} |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 61 | NESTED6; // expected-warning {{anonymous unions are a Microsoft extension}} |
Francois Pichet | 8e161ed | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | void foo() |
| 65 | { |
| 66 | struct test var; |
| 67 | var.a; |
| 68 | var.b; |
| 69 | var.c; |
| 70 | var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}} |
| 71 | var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}} |
| 72 | } |
| 73 | |
Douglas Gregor | 86f208c | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 74 | // Enumeration types with a fixed underlying type. |
| 75 | const int seventeen = 17; |
| 76 | typedef int Int; |
| 77 | |
| 78 | struct X0 { |
| 79 | enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
| 80 | enum E1 : seventeen; |
| 81 | }; |
| 82 | |
Douglas Gregor | 1756ce4 | 2011-02-22 21:42:31 +0000 | [diff] [blame] | 83 | enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
Douglas Gregor | 86f208c | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 84 | SomeValue = 0x100000000 |
| 85 | }; |
Francois Pichet | 83e0995 | 2011-05-11 22:28:19 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | void pointer_to_integral_type_conv(char* ptr) { |
| 89 | char ch = (char)ptr; |
| 90 | short sh = (short)ptr; |
| 91 | ch = (char)ptr; |
| 92 | sh = (short)ptr; |
Hans Wennborg | 649c6c5 | 2013-06-06 09:16:36 +0000 | [diff] [blame] | 93 | |
| 94 | // This is valid ISO C. |
| 95 | _Bool b = (_Bool)ptr; |
Nico Weber | ee625af | 2012-02-01 00:41:00 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
| 99 | typedef struct { |
| 100 | UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}} |
| 101 | } AA; |
| 102 | |
| 103 | typedef struct { |
| 104 | AA; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 105 | } BB; |
Aaron Ballman | 47611c8 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 106 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 107 | struct anon_fault { |
| 108 | struct undefined; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 109 | // expected-error@-1 {{field has incomplete type 'struct undefined'}} |
| 110 | // expected-note@-2 {{forward declaration of 'struct undefined'}} |
| 111 | }; |
| 112 | |
| 113 | const int anon_falt_size = sizeof(struct anon_fault); |
| 114 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 115 | __declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}} |
| 116 | struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}} |
Aaron Ballman | 47611c8 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 117 | |
| 118 | #define MY_TEXT "This is also deprecated" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 119 | __declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}} |
Aaron Ballman | 47611c8 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 120 | |
Aaron Ballman | 3cd6feb | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 121 | struct __declspec(deprecated(123)) DS2 {}; // expected-error {{'deprecated' attribute requires a string}} |
Aaron Ballman | fc685ac | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 122 | |
Aaron Ballman | 47611c8 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 123 | void test( void ) { |
| 124 | e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}} |
| 125 | struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}} |
| 126 | Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}} |
| 127 | |
| 128 | enum DE1 no; // no warning because E1 is not deprecated |
| 129 | } |
Aaron Ballman | aa9df09 | 2013-05-22 23:25:32 +0000 | [diff] [blame] | 130 | |
| 131 | int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}} |
| 132 | // The modifier must follow the asterisk |
| 133 | int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}} |
| 134 | int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}} |
| 135 | int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}} |
| 136 | |
| 137 | // It is illegal to overload based on the type attribute. |
| 138 | void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}} |
| 139 | void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}} |
| 140 | |
| 141 | // It is also illegal to overload based on the pointer type attribute. |
| 142 | void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}} |
| 143 | void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}} |
| 144 | |
| 145 | int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}} |
| 146 | |
| 147 | __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
| 148 | |
| 149 | int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}} |
| 150 | |
| 151 | int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}} |
| 152 | |
| 153 | int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}} |
| 154 | |
| 155 | int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
| 156 | |
| 157 | typedef int *T; |
| 158 | T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 159 | |
| 160 | typedef char *my_va_list; |
| 161 | void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}} |
| 162 | void vmyprintf(const char *f, my_va_list ap); |
| 163 | void myprintf(const char *f, ...) { |
| 164 | my_va_list ap; |
| 165 | if (1) { |
| 166 | __va_start(&ap, f); |
| 167 | vmyprintf(f, ap); |
| 168 | ap = 0; |
| 169 | } else { |
| 170 | __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}} |
| 171 | } |
| 172 | } |