Skip to content

Commit c95189f

Browse files
authored
[clang-tidy] NFCI: remove non-functional matcher from SizeofExpressionCheck (#142654)
This matcher would never match anything, because all record types as-written would be wrapped in an ElaboratedType. Just fixing that leads to a matcher which has too many false positives to be useful. The warning message itself is not great either, it has a hard-coded type name.
1 parent 93314bd commit c95189f

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
170170

171171
const auto PointerToStructType =
172172
hasUnqualifiedDesugaredType(pointerType(pointee(recordType())));
173-
const auto PointerToStructTypeWithBinding =
174-
type(PointerToStructType).bind("struct-type");
175173
const auto PointerToStructExpr =
176174
expr(hasType(hasCanonicalType(PointerToStructType)));
177175

@@ -188,12 +186,10 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
188186
ignoringParenImpCasts(unaryOperator(hasOperatorName("*")));
189187

190188
Finder->addMatcher(
191-
expr(sizeOfExpr(anyOf(has(ignoringParenImpCasts(
192-
expr(PointerToDetectedExpr, unless(DerefExpr),
193-
unless(SubscriptExprWithZeroIndex),
194-
unless(VarWithConstStrLiteralDecl),
195-
unless(cxxThisExpr())))),
196-
has(PointerToStructTypeWithBinding))))
189+
expr(sizeOfExpr(has(ignoringParenImpCasts(expr(
190+
PointerToDetectedExpr, unless(DerefExpr),
191+
unless(SubscriptExprWithZeroIndex),
192+
unless(VarWithConstStrLiteralDecl), unless(cxxThisExpr()))))))
197193
.bind("sizeof-pointer"),
198194
this);
199195
}
@@ -354,16 +350,9 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
354350
"suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
355351
<< E->getSourceRange();
356352
} else if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-pointer")) {
357-
if (Result.Nodes.getNodeAs<Type>("struct-type")) {
358-
diag(E->getBeginLoc(),
359-
"suspicious usage of 'sizeof(A*)' on pointer-to-aggregate type; did "
360-
"you mean 'sizeof(A)'?")
361-
<< E->getSourceRange();
362-
} else {
363-
diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
364-
"of pointer type")
365-
<< E->getSourceRange();
366-
}
353+
diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
354+
"of pointer type")
355+
<< E->getSourceRange();
367356
} else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
368357
"sizeof-compare-constant")) {
369358
diag(E->getOperatorLoc(),

0 commit comments

Comments
 (0)