blob: decd57510f511fdb32c0956fb1a410f7899ea24b [file] [log] [blame]
Francois Pichet913b7bf2010-12-20 03:51:03 +00001// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
Nick Lewycky141ecfe2010-10-12 16:46:35 +00002
3/* Microsoft attribute tests */
4[repeatable][source_annotation_attribute( Parameter|ReturnValue )]
5struct SA_Post{ SA_Post(); int attr; };
6
7[returnvalue:SA_Post( attr=1)]
8int foo1([SA_Post(attr=1)] void *param);
9
10namespace {
11 [returnvalue:SA_Post(attr=1)]
12 int foo2([SA_Post(attr=1)] void *param);
13}
14
15class T {
16 [returnvalue:SA_Post(attr=1)]
17 int foo3([SA_Post(attr=1)] void *param);
18};
19
20extern "C" {
21 [returnvalue:SA_Post(attr=1)]
22 int foo5([SA_Post(attr=1)] void *param);
23}
24
Francois Pichetdfaa5fb2011-01-31 04:54:32 +000025class class_attr {
26public:
27 class_attr([SA_Pre(Null=SA_No,NullTerminated=SA_Yes)] int a)
28 {
29 }
30};
31
32
Nick Lewycky141ecfe2010-10-12 16:46:35 +000033
Francois Pichet913b7bf2010-12-20 03:51:03 +000034void uuidof_test1()
35{
36 __uuidof(0); // expected-error {{you need to include <guiddef.h> before using the '__uuidof' operator}}
37}
38
39typedef struct _GUID
40{
41 unsigned long Data1;
42 unsigned short Data2;
43 unsigned short Data3;
44 unsigned char Data4[8];
45} GUID;
46
47struct __declspec(uuid(L"00000000-0000-0000-1234-000000000047")) uuid_attr_bad1 { };// expected-error {{'uuid' attribute requires parameter 1 to be a string}}
48struct __declspec(uuid(3)) uuid_attr_bad2 { };// expected-error {{'uuid' attribute requires parameter 1 to be a string}}
49struct __declspec(uuid("0000000-0000-0000-1234-0000500000047")) uuid_attr_bad3 { };// expected-error {{uuid attribute contains a malformed GUID}}
50struct __declspec(uuid("0000000-0000-0000-Z234-000000000047")) uuid_attr_bad4 { };// expected-error {{uuid attribute contains a malformed GUID}}
51struct __declspec(uuid("000000000000-0000-1234-000000000047")) uuid_attr_bad5 { };// expected-error {{uuid attribute contains a malformed GUID}}
52
53
54
55struct __declspec(uuid("000000A0-0000-0000-C000-000000000046"))
56struct_with_uuid { };
57struct struct_without_uuid { };
58
Francois Pichet6915c522010-12-27 01:32:00 +000059struct __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
60struct_with_uuid2;
61
62struct
63struct_with_uuid2 {} ;
Francois Pichet913b7bf2010-12-20 03:51:03 +000064
65int uuid_sema_test()
66{
67 struct_with_uuid var_with_uuid[1];
68 struct_without_uuid var_without_uuid[1];
69
70 __uuidof(struct_with_uuid);
Francois Pichet6915c522010-12-27 01:32:00 +000071 __uuidof(struct_with_uuid2);
Francois Pichet913b7bf2010-12-20 03:51:03 +000072 __uuidof(struct_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
73 __uuidof(struct_with_uuid*);
74 __uuidof(struct_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
75
76 __uuidof(var_with_uuid);
77 __uuidof(var_without_uuid);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
78 __uuidof(var_with_uuid[1]);
79 __uuidof(var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
80 __uuidof(&var_with_uuid[1]);
81 __uuidof(&var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
82
83 __uuidof(0);
84 __uuidof(1);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
85}
Francois Pichet6915c522010-12-27 01:32:00 +000086
87
88template <class T>
89void template_uuid()
90{
91 T expr;
92
93 __uuidof(T);
94 __uuidof(expr);
95}
Francois Pichetdbee3412011-01-18 05:04:39 +000096
97
Francois Picheta97d24f2011-04-28 04:39:50 +000098template <class T, const GUID* g = &__uuidof(T)>
99class COM_CLASS_TEMPLATE { };
100
101typedef COM_CLASS_TEMPLATE<struct_with_uuid, &__uuidof(struct_with_uuid)> COM_TYPE_1;
102typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2;
103
104
Francois Pichetdbee3412011-01-18 05:04:39 +0000105
106class CtorCall {
107public:
108 CtorCall& operator=(const CtorCall& that);
109
110 int a;
111};
112
113CtorCall& CtorCall::operator=(const CtorCall& that)
114{
115 if (this != &that) {
116 this->CtorCall::~CtorCall();
117 this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}}
118 }
119 return *this;
120}
Francois Pichet4147d302011-03-27 19:41:34 +0000121
122template <class A>
123class C1 {
124public:
125 template <int B>
126 class Iterator {
127 };
128};
129
130template<class T>
131class C2 {
132 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
133};
134
135template <class T>
136void f(){
137 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
138}
139
Francois Picheta5d318a2011-04-24 11:24:13 +0000140
141
142class AAAA { };
143
144template <class T>
145void redundant_typename() {
146 typename T t;// expected-warning {{expected a qualified name after 'typename'}}
147 typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}}
148 t = 3;
149}
150
Francois Pichet4147d302011-03-27 19:41:34 +0000151int main() {
Francois Picheta5d318a2011-04-24 11:24:13 +0000152 redundant_typename<int>();
Francois Pichet4147d302011-03-27 19:41:34 +0000153 f<int>();
154}
155
156
Francois Pichet00470122011-04-27 05:07:51 +0000157__interface MicrosoftInterface;
158__interface MicrosoftInterface {
159 virtual void foo1() = 0;
160 virtual void foo2() = 0;
Francois Pichet338d7f72011-04-28 01:59:37 +0000161};
162
163__int64 x7 = __int64(0);