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
5 
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
12 
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"
18 
19 
20 // expected-no-diagnostics
21 
22 // Both type and name contains "kind".
23 struct UnionLikeStruct1 {
24   enum Kind {
25     volume,
26     area
27   } kind;
28 
29   int Volume;
30   int Area;
31 
UnionLikeStruct1UnionLikeStruct132   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;
40     }
41   }
42 };
43 
fUnionLikeStruct1()44 void fUnionLikeStruct1() {
45   UnionLikeStruct1 t(UnionLikeStruct1::volume, 10);
46 }
47 
48 // Only name contains "kind".
49 struct UnionLikeStruct2 {
50   enum Type {
51     volume,
52     area
53   } kind;
54 
55   int Volume;
56   int Area;
57 
UnionLikeStruct2UnionLikeStruct258   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;
66     }
67   }
68 };
69 
fUnionLikeStruct2()70 void fUnionLikeStruct2() {
71   UnionLikeStruct2 t(UnionLikeStruct2::volume, 10);
72 }
73 
74 // Only type contains "kind".
75 struct UnionLikeStruct3 {
76   enum Kind {
77     volume,
78     area
79   } type;
80 
81   int Volume;
82   int Area;
83 
UnionLikeStruct3UnionLikeStruct384   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;
92     }
93   }
94 };
95 
fUnionLikeStruct3()96 void fUnionLikeStruct3() {
97   UnionLikeStruct3 t(UnionLikeStruct3::volume, 10);
98 }
99 
100 // Only type contains "tag".
101 struct UnionLikeStruct4 {
102   enum Tag {
103     volume,
104     area
105   } type;
106 
107   int Volume;
108   int Area;
109 
UnionLikeStruct4UnionLikeStruct4110   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;
118     }
119   }
120 };
121 
fUnionLikeStruct4()122 void fUnionLikeStruct4() {
123   UnionLikeStruct4 t(UnionLikeStruct4::volume, 10);
124 }
125 
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;
132 
133   int Volume;
134   int Area;
135 
UnionLikeStruct5UnionLikeStruct5136   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;
144     }
145   }
146 };
147 
fUnionLikeStruct5()148 void fUnionLikeStruct5() {
149   UnionLikeStruct5 t(UnionLikeStruct5::volume, 10);
150 }
151