[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / cxx-uninitialized-object-unionlike-constructs.cpp
blob92412f7cccb9d8be6c9548a90371019c8d67c075
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
2 // RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
3 // RUN: -analyzer-config optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind" \
4 // RUN: -std=c++11 -verify %s
6 // RUN: not %clang_analyze_cc1 -verify %s \
7 // RUN: -analyzer-checker=core \
8 // RUN: -analyzer-checker=optin.cplusplus.UninitializedObject \
9 // RUN: -analyzer-config \
10 // RUN: optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="([)]" \
11 // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-UNINIT-INVALID-REGEX
13 // CHECK-UNINIT-INVALID-REGEX: (frontend): invalid input for checker option
14 // CHECK-UNINIT-INVALID-REGEX-SAME: 'optin.cplusplus.UninitializedObject:IgnoreRecordsWithField',
15 // CHECK-UNINIT-INVALID-REGEX-SAME: that expects a valid regex, building failed
16 // CHECK-UNINIT-INVALID-REGEX-SAME: with error message "parentheses not
17 // CHECK-UNINIT-INVALID-REGEX-SAME: balanced"
20 // expected-no-diagnostics
22 // Both type and name contains "kind".
23 struct UnionLikeStruct1 {
24 enum Kind {
25 volume,
26 area
27 } kind;
29 int Volume;
30 int Area;
32 UnionLikeStruct1(Kind kind, int Val) : kind(kind) {
33 switch (kind) {
34 case volume:
35 Volume = Val;
36 break;
37 case area:
38 Area = Val;
39 break;
44 void fUnionLikeStruct1() {
45 UnionLikeStruct1 t(UnionLikeStruct1::volume, 10);
48 // Only name contains "kind".
49 struct UnionLikeStruct2 {
50 enum Type {
51 volume,
52 area
53 } kind;
55 int Volume;
56 int Area;
58 UnionLikeStruct2(Type kind, int Val) : kind(kind) {
59 switch (kind) {
60 case volume:
61 Volume = Val;
62 break;
63 case area:
64 Area = Val;
65 break;
70 void fUnionLikeStruct2() {
71 UnionLikeStruct2 t(UnionLikeStruct2::volume, 10);
74 // Only type contains "kind".
75 struct UnionLikeStruct3 {
76 enum Kind {
77 volume,
78 area
79 } type;
81 int Volume;
82 int Area;
84 UnionLikeStruct3(Kind type, int Val) : type(type) {
85 switch (type) {
86 case volume:
87 Volume = Val;
88 break;
89 case area:
90 Area = Val;
91 break;
96 void fUnionLikeStruct3() {
97 UnionLikeStruct3 t(UnionLikeStruct3::volume, 10);
100 // Only type contains "tag".
101 struct UnionLikeStruct4 {
102 enum Tag {
103 volume,
104 area
105 } type;
107 int Volume;
108 int Area;
110 UnionLikeStruct4(Tag type, int Val) : type(type) {
111 switch (type) {
112 case volume:
113 Volume = Val;
114 break;
115 case area:
116 Area = Val;
117 break;
122 void fUnionLikeStruct4() {
123 UnionLikeStruct4 t(UnionLikeStruct4::volume, 10);
126 // Both name and type name contains but does not equal to tag/kind.
127 struct UnionLikeStruct5 {
128 enum WhateverTagBlahBlah {
129 volume,
130 area
131 } FunnyKindName;
133 int Volume;
134 int Area;
136 UnionLikeStruct5(WhateverTagBlahBlah type, int Val) : FunnyKindName(type) {
137 switch (FunnyKindName) {
138 case volume:
139 Volume = Val;
140 break;
141 case area:
142 Area = Val;
143 break;
148 void fUnionLikeStruct5() {
149 UnionLikeStruct5 t(UnionLikeStruct5::volume, 10);