blob: 5215e72b1bac64118cf67b8b394794a156dbbad3 [file] [log] [blame]
Francois Pichet0c71f6c2010-11-23 06:07:27 +00001// RUN: %clang_cc1 %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
23
Francois Pichet0c71f6c2010-11-23 06:07:27 +000024
25
26
27
28typedef struct notnested {
29 long bad1;
30 long bad2;
31} NOTNESTED;
32
33
34typedef struct nested1 {
35 long a;
36 struct notnested var1;
37 NOTNESTED var2;
38} NESTED1;
39
40struct nested2 {
41 long b;
42 NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}}
43};
44
45struct test {
46 int c;
47 struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}}
48};
49
50void foo()
51{
52 struct test var;
53 var.a;
54 var.b;
55 var.c;
56 var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}}
57 var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}}
58}
59
Douglas Gregora1aec292011-02-22 20:32:04 +000060// Enumeration types with a fixed underlying type.
61const int seventeen = 17;
62typedef int Int;
63
64struct X0 {
65 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
66 enum E1 : seventeen;
67};
68
Douglas Gregor996a735b2011-02-22 21:42:31 +000069enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
Douglas Gregora1aec292011-02-22 20:32:04 +000070 SomeValue = 0x100000000
71};
Francois Pichet6f7289d2011-05-11 22:28:19 +000072
73
74void pointer_to_integral_type_conv(char* ptr) {
75 char ch = (char)ptr;
76 short sh = (short)ptr;
77 ch = (char)ptr;
78 sh = (short)ptr;
Hans Wennborg15439bc2013-06-06 09:16:36 +000079
80 // This is valid ISO C.
81 _Bool b = (_Bool)ptr;
Nico Weberf8bb3de2012-02-01 00:41:00 +000082}
83
84
85typedef struct {
86 UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}}
87} AA;
88
89typedef struct {
90 AA; // expected-warning {{anonymous structs are a Microsoft extension}}
91} BB;
Aaron Ballman96e7c092012-02-23 01:19:31 +000092
Fariborz Jahanian08a1eb72012-04-23 20:30:52 +000093__declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' declared here}}
Eli Friedman971bfa12012-08-08 21:52:41 +000094struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{declared here}}
Aaron Ballman96e7c092012-02-23 01:19:31 +000095
96#define MY_TEXT "This is also deprecated"
Fariborz Jahanian08a1eb72012-04-23 20:30:52 +000097__declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' declared here}}
Aaron Ballman96e7c092012-02-23 01:19:31 +000098
Aaron Ballman478faed2012-06-19 22:09:27 +000099struct __declspec(deprecated(123)) DS2 {}; // expected-error {{argument to deprecated attribute was not a string literal}}
100
Aaron Ballman96e7c092012-02-23 01:19:31 +0000101void test( void ) {
102 e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}}
103 struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}}
104 Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}}
105
106 enum DE1 no; // no warning because E1 is not deprecated
107}
Aaron Ballman317a77f2013-05-22 23:25:32 +0000108
109int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
110// The modifier must follow the asterisk
111int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
112int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}}
113int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}}
114
115// It is illegal to overload based on the type attribute.
116void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}}
117void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}}
118
119// It is also illegal to overload based on the pointer type attribute.
120void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}}
121void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
122
123int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
124
125__ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
126
127int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
128
129int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
130
131int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}}
132
133int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
134
135typedef int *T;
136T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}