1// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-tagged-union-member-count %t \
2// RUN: -config='{CheckOptions: { \
3// RUN: bugprone-tagged-union-member-count.StrictMode: true, \
4// RUN: bugprone-tagged-union-member-count.EnableCountingEnumHeuristic: false, \
5// RUN: }}' --
6
7// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: tagged union has fewer data members (3) than tags (4)
8struct IncorrectBecauseHeuristicIsDisabledPrefixCase {
9 enum {
10 tags11,
11 tags22,
12 tags33,
13 lasttag,
14 } Tags;
15 union {
16 char A;
17 short B;
18 int C;
19 } Data;
20};
21
22struct CorrectBecauseHeuristicIsDisabledPrefixCase { // No warnings expected
23 enum {
24 tags1,
25 tags2,
26 tags3,
27 lasttags,
28 } Tags;
29 union {
30 char A;
31 short B;
32 int C;
33 long D;
34 } Data;
35};
36
37// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: tagged union has fewer data members (3) than tags (4)
38struct IncorrectBecauseHeuristicIsDisabledSuffixCase {
39 enum {
40 tags11,
41 tags22,
42 tags33,
43 tags_count,
44 } Tags;
45 union {
46 char A;
47 short B;
48 int C;
49 } Data;
50};
51
52struct CorrectBecauseHeuristicIsDisabledSuffixCase { // No warnings expected
53 enum {
54 tags1,
55 tags2,
56 tags3,
57 tags_count,
58 } Tags;
59 union {
60 char A;
61 short B;
62 int C;
63 long D;
64 } Data;
65};
66

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-counting-enum-heuristic-is-disabled.cpp