Francois Pichet | 0c71f6c | 2010-11-23 06:07:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions |
Chandler Carruth | a64aedb | 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 | a310806 | 2010-10-18 15:01:13 +0000 | [diff] [blame] | 22 | |
Aaron Ballman | df8fe4c | 2013-11-24 21:35:16 +0000 | [diff] [blame] | 23 | struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */ |
Francois Pichet | 0c71f6c | 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 | |
| 42 | struct test { |
| 43 | int c; |
| 44 | struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 45 | }; |
| 46 | |
| 47 | void foo() |
| 48 | { |
| 49 | struct test var; |
| 50 | var.a; |
| 51 | var.b; |
| 52 | var.c; |
| 53 | var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}} |
| 54 | var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}} |
| 55 | } |
| 56 | |
Douglas Gregor | a1aec29 | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 57 | // Enumeration types with a fixed underlying type. |
| 58 | const int seventeen = 17; |
| 59 | typedef int Int; |
| 60 | |
| 61 | struct X0 { |
| 62 | enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
| 63 | enum E1 : seventeen; |
| 64 | }; |
| 65 | |
Douglas Gregor | 996a735b | 2011-02-22 21:42:31 +0000 | [diff] [blame] | 66 | enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
Douglas Gregor | a1aec29 | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 67 | SomeValue = 0x100000000 |
| 68 | }; |
Francois Pichet | 6f7289d | 2011-05-11 22:28:19 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | void pointer_to_integral_type_conv(char* ptr) { |
| 72 | char ch = (char)ptr; |
| 73 | short sh = (short)ptr; |
| 74 | ch = (char)ptr; |
| 75 | sh = (short)ptr; |
Hans Wennborg | 15439bc | 2013-06-06 09:16:36 +0000 | [diff] [blame] | 76 | |
| 77 | // This is valid ISO C. |
| 78 | _Bool b = (_Bool)ptr; |
Nico Weber | f8bb3de | 2012-02-01 00:41:00 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
| 82 | typedef struct { |
| 83 | UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}} |
| 84 | } AA; |
| 85 | |
| 86 | typedef struct { |
| 87 | AA; // expected-warning {{anonymous structs are a Microsoft extension}} |
| 88 | } BB; |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 89 | |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 90 | __declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}} |
| 91 | struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}} |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 92 | |
| 93 | #define MY_TEXT "This is also deprecated" |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 94 | __declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}} |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 95 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 96 | struct __declspec(deprecated(123)) DS2 {}; // expected-error {{'deprecated' attribute requires a string}} |
Aaron Ballman | 478faed | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 97 | |
Aaron Ballman | 96e7c09 | 2012-02-23 01:19:31 +0000 | [diff] [blame] | 98 | void test( void ) { |
| 99 | e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}} |
| 100 | struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}} |
| 101 | Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}} |
| 102 | |
| 103 | enum DE1 no; // no warning because E1 is not deprecated |
| 104 | } |
Aaron Ballman | 317a77f | 2013-05-22 23:25:32 +0000 | [diff] [blame] | 105 | |
| 106 | int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}} |
| 107 | // The modifier must follow the asterisk |
| 108 | int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}} |
| 109 | int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}} |
| 110 | int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}} |
| 111 | |
| 112 | // It is illegal to overload based on the type attribute. |
| 113 | void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}} |
| 114 | void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}} |
| 115 | |
| 116 | // It is also illegal to overload based on the pointer type attribute. |
| 117 | void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}} |
| 118 | void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}} |
| 119 | |
| 120 | int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}} |
| 121 | |
| 122 | __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
| 123 | |
| 124 | int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}} |
| 125 | |
| 126 | int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}} |
| 127 | |
| 128 | int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}} |
| 129 | |
| 130 | int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
| 131 | |
| 132 | typedef int *T; |
| 133 | T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}} |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 134 | |
| 135 | typedef char *my_va_list; |
Reid Kleckner | 55e3cec | 2014-03-26 22:52:23 +0000 | [diff] [blame^] | 136 | void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}} |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 137 | void vmyprintf(const char *f, my_va_list ap); |
| 138 | void myprintf(const char *f, ...) { |
| 139 | my_va_list ap; |
| 140 | if (1) { |
| 141 | __va_start(&ap, f); |
| 142 | vmyprintf(f, ap); |
| 143 | ap = 0; |
| 144 | } else { |
| 145 | __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}} |
| 146 | } |
| 147 | } |