================
@@ -0,0 +1,181 @@
+// RUN: %check_clang_tidy %s bugprone-tagged-union-member-count %t
+
+enum tags3 {
+       tags3_1,
+       tags3_2,
+       tags3_3,
+};
+
+enum tags4 {
+       tags4_1,
+       tags4_2,
+       tags4_3,
+       tags4_4,
+};
+
+enum tags5 {
+       tags5_1,
+       tags5_2,
+       tags5_3,
+       tags5_4,
+       tags5_5,
+};
+
+union union3 {
+       short *shorts;
+       int *ints;
+       float *floats;
+};
+
+union union4 {
+       short *shorts;
+       double *doubles;
+       int *ints;
+       float *floats;
+};
+
+// It is not obvious which enum is the tag for the union.
+struct taggedunion2 { // No warnings expected.
+       enum tags3 tagA;
+       enum tags4 tagB;
+       union union4 data;
+};
+
+// It is not obvious which union does the tag belong to.
+struct taggedunion4 { // No warnings expected.
+       enum tags3 tag;
+       union union3 dataB;
+       union union3 dataA;
+};
+
+struct taggedunion1 { // CHECK-MESSAGES: :[[@LINE]]:8: warning: Tagged union 
has more data members than tags! Data members: 4 Tags: 3 
[bugprone-tagged-union-member-count]
+       enum tags3 tag;
+    union union4 data;
+};
+
+struct taggedunion5 { // CHECK-MESSAGES: :[[@LINE]]:8: warning: Tagged union 
has more data members than tags! Data members: 4 Tags: 3 
[bugprone-tagged-union-member-count]
+       enum tags3 tag;
----------------
PiotrZSL wrote:

run clang-format on this file (you may need to move it somewere to overcome 
clang-format exclude of test directory, just to format it and bring it back 
again)

https://github.com/llvm/llvm-project/pull/89925
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to