| 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: false, \ |
| 4 | // RUN: bugprone-tagged-union-member-count.EnableCountingEnumHeuristic: true, \ |
| 5 | // RUN: bugprone-tagged-union-member-count.CountingEnumSuffixes: "count", \ |
| 6 | // RUN: bugprone-tagged-union-member-count.CountingEnumPrefixes: "last", \ |
| 7 | // RUN: }}' -- |
| 8 | |
| 9 | union Union3 { |
| 10 | short *Shorts; |
| 11 | int *Ints; |
| 12 | float *Floats; |
| 13 | }; |
| 14 | |
| 15 | union Union4 { |
| 16 | short *Shorts; |
| 17 | double *Doubles; |
| 18 | int *Ints; |
| 19 | float *Floats; |
| 20 | }; |
| 21 | |
| 22 | // The heuristic only considers the last enum constant |
| 23 | // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: tagged union has more data members (4) than tags (3) |
| 24 | struct TaggedUnionPrefixAndSuffixMatch { |
| 25 | enum { |
| 26 | tags1, |
| 27 | tags2, |
| 28 | tagscount, |
| 29 | lasttags |
| 30 | } Kind; |
| 31 | Union4 Data; |
| 32 | }; |
| 33 | |
| 34 | // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: tagged union has more data members (3) than tags (2) |
| 35 | struct TaggedUnionOnlyPrefixMatch { |
| 36 | enum { |
| 37 | prefixtag1, |
| 38 | prefixtag2, |
| 39 | lastprefixtag |
| 40 | } Kind; |
| 41 | Union3 Data; |
| 42 | }; |
| 43 | |
| 44 | // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: tagged union has more data members (3) than tags (2) |
| 45 | struct TaggedUnionOnlySuffixMatch { |
| 46 | enum { |
| 47 | suffixtag1, |
| 48 | suffixtag2, |
| 49 | suffixtagcount |
| 50 | } Kind; |
| 51 | Union3 Data; |
| 52 | }; |
| 53 | |