[all-commits] [llvm/llvm-project] 7b8f7b: [clang-tidy] Add new check bugprone-tagged-union-m...
tigbr via All-commits
all-commits at lists.llvm.org
Tue Oct 1 04:24:53 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 7b8f7beadcf1814b1f1aa985d344ca17747531a7
https://github.com/llvm/llvm-project/commit/7b8f7beadcf1814b1f1aa985d344ca17747531a7
Author: tigbr <160260245+tigbr at users.noreply.github.com>
Date: 2024-10-01 (Tue, 01 Oct 2024)
Changed paths:
M clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
M clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
A clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
A clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.h
M clang-tools-extra/docs/ReleaseNotes.rst
A clang-tools-extra/docs/clang-tidy/checks/bugprone/tagged-union-member-count.rst
M clang-tools-extra/docs/clang-tidy/checks/list.rst
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-counting-enum-heuristic-bad-config.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-counting-enum-heuristic-is-disabled.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-counting-enum-heuristic-is-enabled.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-counting-enum-prefixes-and-suffixes.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-counting-enum-prefixes.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-counting-enum-suffixes.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-strictmode-is-disabled.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count-strictmode-is-enabled.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count.c
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count.cpp
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count.m
A clang-tools-extra/test/clang-tidy/checkers/bugprone/tagged-union-member-count.mm
Log Message:
-----------
[clang-tidy] Add new check bugprone-tagged-union-member-count (#89925)
This patch introduces a new check to find mismatches between the number
of data members in a union and the number enum values present in
variant-like structures.
Variant-like types can look something like this:
```c++
struct variant {
enum {
tag1,
tag2,
} kind;
union {
int i;
char c;
} data;
};
```
The kind data member of the variant is supposed to tell which data
member of the union is valid, however if there are fewer enum values
than union members, then it is likely a mistake.
The opposite is not that obvious, because it might be fine to have more
enum values than union data members, but for the time being I am curious
how many real bugs can be caught if we give a warning regardless.
This patch also contains a heuristic where we try to guess whether the
last enum constant is actually supposed to be a tag value for the
variant or whether it is just holding how many enum constants have been
created.
Patch by Gábor Tóthvári!
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list