1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ 2 // RUN: -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ 3 // RUN: -analyzer-config alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind" \ 4 // RUN: -std=c++11 -verify %s 5 6 // expected-no-diagnostics 7 8 // Both type and name contains "kind". 9 struct UnionLikeStruct1 { 10 enum Kind { 11 volume, 12 area 13 } kind; 14 15 int Volume; 16 int Area; 17 18 UnionLikeStruct1(Kind kind, int Val) : kind(kind) { 19 switch (kind) { 20 case volume: 21 Volume = Val; 22 break; 23 case area: 24 Area = Val; 25 break; 26 } 27 } 28 }; 29 30 void fUnionLikeStruct1() { 31 UnionLikeStruct1 t(UnionLikeStruct1::volume, 10); 32 } 33 34 // Only name contains "kind". 35 struct UnionLikeStruct2 { 36 enum Type { 37 volume, 38 area 39 } kind; 40 41 int Volume; 42 int Area; 43 44 UnionLikeStruct2(Type kind, int Val) : kind(kind) { 45 switch (kind) { 46 case volume: 47 Volume = Val; 48 break; 49 case area: 50 Area = Val; 51 break; 52 } 53 } 54 }; 55 56 void fUnionLikeStruct2() { 57 UnionLikeStruct2 t(UnionLikeStruct2::volume, 10); 58 } 59 60 // Only type contains "kind". 61 struct UnionLikeStruct3 { 62 enum Kind { 63 volume, 64 area 65 } type; 66 67 int Volume; 68 int Area; 69 70 UnionLikeStruct3(Kind type, int Val) : type(type) { 71 switch (type) { 72 case volume: 73 Volume = Val; 74 break; 75 case area: 76 Area = Val; 77 break; 78 } 79 } 80 }; 81 82 void fUnionLikeStruct3() { 83 UnionLikeStruct3 t(UnionLikeStruct3::volume, 10); 84 } 85 86 // Only type contains "tag". 87 struct UnionLikeStruct4 { 88 enum Tag { 89 volume, 90 area 91 } type; 92 93 int Volume; 94 int Area; 95 96 UnionLikeStruct4(Tag type, int Val) : type(type) { 97 switch (type) { 98 case volume: 99 Volume = Val; 100 break; 101 case area: 102 Area = Val; 103 break; 104 } 105 } 106 }; 107 108 void fUnionLikeStruct4() { 109 UnionLikeStruct4 t(UnionLikeStruct4::volume, 10); 110 } 111 112 // Both name and type name contains but does not equal to tag/kind. 113 struct UnionLikeStruct5 { 114 enum WhateverTagBlahBlah { 115 volume, 116 area 117 } FunnyKindName; 118 119 int Volume; 120 int Area; 121 122 UnionLikeStruct5(WhateverTagBlahBlah type, int Val) : FunnyKindName(type) { 123 switch (FunnyKindName) { 124 case volume: 125 Volume = Val; 126 break; 127 case area: 128 Area = Val; 129 break; 130 } 131 } 132 }; 133 134 void fUnionLikeStruct5() { 135 UnionLikeStruct5 t(UnionLikeStruct5::volume, 10); 136 } 137