You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-union-access.cpp
+11-4Lines changed: 11 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,10 @@ union U {
5
5
char union_member2;
6
6
} u;
7
7
8
+
union W {
9
+
template <classTP> operator TP *() const;
10
+
};
11
+
8
12
structS {
9
13
int non_union_member;
10
14
union {
@@ -20,22 +24,25 @@ void f(char);
20
24
voidf2(U);
21
25
voidf3(U&);
22
26
voidf4(U*);
27
+
W f5();
23
28
24
29
voidcheck()
25
30
{
26
31
u.union_member1 = true;
27
-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]
32
+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not access members of unions; consider using (boost::)variant instead [cppcoreguidelines-pro-type-union-access]
28
33
auto b = u.union_member2;
29
-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not access members of unions; use (boost::)variant instead
34
+
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not access members of unions; consider using (boost::)variant instead
30
35
auto a = &s.union_member;
31
-
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; use (boost::)variant instead
36
+
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; consider using (boost::)variant instead
32
37
f(s.u.union_member2);
33
-
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not access members of unions; use (boost::)variant instead
38
+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not access members of unions; consider using (boost::)variant instead
34
39
35
40
s.non_union_member = 2; // OK
36
41
37
42
U u2 = u; // OK
38
43
f2(u); // OK
39
44
f3(u); // OK
40
45
f4(&u); // OK
46
+
void *ret = f5();
47
+
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; consider using (boost::)variant instead
0 commit comments