@@ -17,14 +17,10 @@ namespace clang::tidy::bugprone {
17
17
18
18
namespace {
19
19
20
- AST_MATCHER (Type, charType) {
21
- return Node.isCharType ();
22
- }
23
- AST_MATCHER (Type, unionType) {
24
- return Node.isUnionType ();
25
- }
20
+ AST_MATCHER (Type, charType) { return Node.isCharType (); }
21
+ AST_MATCHER (Type, unionType) { return Node.isUnionType (); }
26
22
27
- }
23
+ } // namespace
28
24
29
25
CastToStructCheck::CastToStructCheck (StringRef Name, ClangTidyContext *Context)
30
26
: ClangTidyCheck(Name, Context),
@@ -49,9 +45,7 @@ void CastToStructCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
49
45
void CastToStructCheck::registerMatchers (MatchFinder *Finder) {
50
46
auto FromPointee =
51
47
qualType (hasUnqualifiedDesugaredType (type ().bind (" FromType" )),
52
- unless (voidType ()),
53
- unless (charType ()),
54
- unless (unionType ()))
48
+ unless (voidType ()), unless (charType ()), unless (unionType ()))
55
49
.bind (" FromPointee" );
56
50
auto ToPointee =
57
51
qualType (hasUnqualifiedDesugaredType (
@@ -77,7 +71,8 @@ void CastToStructCheck::check(const MatchFinder::MatchResult &Result) {
77
71
if (FromType == ToType)
78
72
return ;
79
73
80
- auto CheckNameIgnore = [this ](const std::string &FromName, const std::string &ToName) {
74
+ auto CheckNameIgnore = [this ](const std::string &FromName,
75
+ const std::string &ToName) {
81
76
bool FromMatch = false ;
82
77
for (auto [Idx, Regex] : llvm::enumerate (IgnoredCastsRegex)) {
83
78
if (Idx % 2 == 0 ) {
@@ -93,10 +88,9 @@ void CastToStructCheck::check(const MatchFinder::MatchResult &Result) {
93
88
if (CheckNameIgnore (FromPtr->getAsString (), ToPtr->getAsString ()))
94
89
return ;
95
90
96
- diag (FoundCastExpr->getExprLoc (),
97
- " casting a %0 pointer to a "
98
- " %1 pointer and accessing a field can lead to memory "
99
- " access errors or data corruption" )
91
+ diag (FoundCastExpr->getExprLoc (), " casting a %0 pointer to a "
92
+ " %1 pointer can lead to memory "
93
+ " access errors or data corruption" )
100
94
<< *FromPtr << *ToPtr;
101
95
}
102
96
0 commit comments