annotate clang/test/SemaCXX/ms-uuid.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 0572611fdcc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -Wno-deprecated-declarations
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify -fms-extensions %s -Wno-deprecated-declarations
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 typedef struct _GUID {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
5 __UINT32_TYPE__ Data1;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
6 __UINT16_TYPE__ Data2;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
7 __UINT16_TYPE__ Data3;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
8 __UINT8_TYPE__ Data4[8];
150
anatofuz
parents:
diff changeset
9 } GUID;
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 namespace {
anatofuz
parents:
diff changeset
12 // cl.exe's behavior with merging uuid attributes is a bit erratic:
anatofuz
parents:
diff changeset
13 // * In []-style attributes, a single [] list must not list a duplicate uuid
anatofuz
parents:
diff changeset
14 // (even if it's the same uuid), and only a single declaration of a class
anatofuz
parents:
diff changeset
15 // must have a uuid else the compiler errors out (even if two declarations of
anatofuz
parents:
diff changeset
16 // a class have the same uuid).
anatofuz
parents:
diff changeset
17 // * For __declspec(uuid(...)), it's ok if several declarations of a class have
anatofuz
parents:
diff changeset
18 // an uuid, as long as it's the same uuid each time. If uuids on declarations
anatofuz
parents:
diff changeset
19 // don't match, the compiler errors out.
anatofuz
parents:
diff changeset
20 // * If there are several __declspec(uuid(...))s on one declaration, the
anatofuz
parents:
diff changeset
21 // compiler only warns about this and uses the last uuid. It even warns if
anatofuz
parents:
diff changeset
22 // the uuids are the same.
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 // clang-cl implements the following simpler (but largely compatible) behavior
anatofuz
parents:
diff changeset
25 // instead:
anatofuz
parents:
diff changeset
26 // * [] and __declspec uuids have the same behavior.
anatofuz
parents:
diff changeset
27 // * If there are several uuids on a class (no matter if on the same decl or
anatofuz
parents:
diff changeset
28 // on several decls), it is an error if they don't match.
anatofuz
parents:
diff changeset
29 // * Having several uuids that match is ok.
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 // Both cl and clang-cl accept this:
anatofuz
parents:
diff changeset
32 class __declspec(uuid("000000A0-0000-0000-C000-000000000049")) C1;
anatofuz
parents:
diff changeset
33 class __declspec(uuid("000000a0-0000-0000-c000-000000000049")) C1;
anatofuz
parents:
diff changeset
34 class __declspec(uuid("{000000a0-0000-0000-C000-000000000049}")) C1;
anatofuz
parents:
diff changeset
35 class __declspec(uuid("000000A0-0000-0000-C000-000000000049")) C1 {};
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 // Both cl and clang-cl error out on this:
anatofuz
parents:
diff changeset
38 // expected-note@+1 2{{previous uuid specified here}}
anatofuz
parents:
diff changeset
39 class __declspec(uuid("000000A0-0000-0000-C000-000000000049")) C2;
anatofuz
parents:
diff changeset
40 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
41 class __declspec(uuid("110000A0-0000-0000-C000-000000000049")) C2;
anatofuz
parents:
diff changeset
42 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
43 class __declspec(uuid("220000A0-0000-0000-C000-000000000049")) C2 {};
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 // expected-note@+1 {{previous uuid specified here}}
anatofuz
parents:
diff changeset
46 class __declspec(uuid("000000A0-0000-0000-C000-000000000049")) C2_2;
anatofuz
parents:
diff changeset
47 class C2_2;
anatofuz
parents:
diff changeset
48 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
49 class __declspec(uuid("110000A0-0000-0000-C000-000000000049")) C2_2;
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 // clang-cl accepts this, but cl errors out:
anatofuz
parents:
diff changeset
52 [uuid("000000A0-0000-0000-C000-000000000049")] class C3;
anatofuz
parents:
diff changeset
53 [uuid("000000A0-0000-0000-C000-000000000049")] class C3;
anatofuz
parents:
diff changeset
54 [uuid("000000A0-0000-0000-C000-000000000049")] class C3 {};
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 // Both cl and clang-cl error out on this (but for different reasons):
anatofuz
parents:
diff changeset
57 // expected-note@+1 2{{previous uuid specified here}}
anatofuz
parents:
diff changeset
58 [uuid("000000A0-0000-0000-C000-000000000049")] class C4;
anatofuz
parents:
diff changeset
59 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
60 [uuid("110000A0-0000-0000-C000-000000000049")] class C4;
anatofuz
parents:
diff changeset
61 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
62 [uuid("220000A0-0000-0000-C000-000000000049")] class C4 {};
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 // Both cl and clang-cl error out on this:
anatofuz
parents:
diff changeset
65 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
66 class __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
anatofuz
parents:
diff changeset
67 // expected-note@+1 {{previous uuid specified here}}
anatofuz
parents:
diff changeset
68 __declspec(uuid("110000A0-0000-0000-C000-000000000049")) C5;
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
71 [uuid("000000A0-0000-0000-C000-000000000049"),
anatofuz
parents:
diff changeset
72 // expected-note@+1 {{previous uuid specified here}}
anatofuz
parents:
diff changeset
73 uuid("110000A0-0000-0000-C000-000000000049")] class C6;
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 // cl doesn't diagnose having one uuid each as []-style attributes and as
anatofuz
parents:
diff changeset
76 // __declspec, even if the uuids differ. clang-cl errors if they differ.
anatofuz
parents:
diff changeset
77 [uuid("000000A0-0000-0000-C000-000000000049")]
anatofuz
parents:
diff changeset
78 class __declspec(uuid("000000A0-0000-0000-C000-000000000049")) C7;
anatofuz
parents:
diff changeset
79
anatofuz
parents:
diff changeset
80 // expected-note@+1 {{previous uuid specified here}}
anatofuz
parents:
diff changeset
81 [uuid("000000A0-0000-0000-C000-000000000049")]
anatofuz
parents:
diff changeset
82 // expected-error@+1 {{uuid does not match previous declaration}}
anatofuz
parents:
diff changeset
83 class __declspec(uuid("110000A0-0000-0000-C000-000000000049")) C8;
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85
anatofuz
parents:
diff changeset
86 // cl warns on this, but clang-cl is fine with it (which is consistent with
anatofuz
parents:
diff changeset
87 // e.g. specifying __multiple_inheritance several times, which cl accepts
anatofuz
parents:
diff changeset
88 // without warning too).
anatofuz
parents:
diff changeset
89 class __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
anatofuz
parents:
diff changeset
90 __declspec(uuid("000000A0-0000-0000-C000-000000000049")) C9;
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 // cl errors out on this, but clang-cl is fine with it (to be consistent with
anatofuz
parents:
diff changeset
93 // the previous case).
anatofuz
parents:
diff changeset
94 [uuid("000000A0-0000-0000-C000-000000000049"),
anatofuz
parents:
diff changeset
95 uuid("000000A0-0000-0000-C000-000000000049")] class C10;
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 template <const GUID* p>
anatofuz
parents:
diff changeset
98 void F1() {
anatofuz
parents:
diff changeset
99 // Regression test for PR24986. The given GUID should just work as a pointer.
anatofuz
parents:
diff changeset
100 const GUID* q = p;
anatofuz
parents:
diff changeset
101 }
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 void F2() {
anatofuz
parents:
diff changeset
104 // The UUID should work for a non-type template parameter.
anatofuz
parents:
diff changeset
105 F1<&__uuidof(C1)>();
anatofuz
parents:
diff changeset
106 }
anatofuz
parents:
diff changeset
107
anatofuz
parents:
diff changeset
108 }
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 // Test class/struct redeclaration where the subsequent
anatofuz
parents:
diff changeset
111 // declaration has a uuid attribute
anatofuz
parents:
diff changeset
112 struct X{};
anatofuz
parents:
diff changeset
113
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
114 struct __declspec(uuid("00000000-0000-0000-0000-000000000000")) X;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
115
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
116 namespace ConstantEvaluation {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
117 class __declspec(uuid("1babb1ed-feed-c01d-1ced-decafc0ffee5")) Request;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
118 constexpr GUID a = __uuidof(Request);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
119 static_assert(a.Data1 == 0x1babb1ed, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
120 static_assert(__uuidof(Request).Data1 == 0x1babb1ed, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
121 static_assert(a.Data2 == 0xfeed, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
122 static_assert(__uuidof(Request).Data2 == 0xfeed, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
123 static_assert(a.Data3 == 0xc01d, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
124 static_assert(__uuidof(Request).Data3 == 0xc01d, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
125 static_assert(a.Data4[0] == 0x1c, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
126 static_assert(__uuidof(Request).Data4[0] == 0x1c, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
127 static_assert(a.Data4[1] == 0xed, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
128 static_assert(__uuidof(Request).Data4[1] == 0xed, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
129 static_assert(a.Data4[2] == 0xde, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
130 static_assert(__uuidof(Request).Data4[2] == 0xde, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
131 static_assert(a.Data4[7] == 0xe5, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
132 static_assert(__uuidof(Request).Data4[7] == 0xe5, "");
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
133 constexpr int k = __uuidof(Request).Data4[8]; // expected-error {{constant expression}} expected-note {{past-the-end}}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
134 }