danielmarjamaki created this revision.
Herald added a subscriber: JDevlieghere.
This patch fixes https://bugs.llvm.org/show_bug.cgi?id=32246
To avoid spurious warnings, clang-tidy should not warn about misplaced widening
casts for implicit casts in function calls.
Repository:
rL LLVM
https://reviews.llvm.org/D31097
Files:
clang-tidy/misc/MisplacedWideningCastCheck.cpp
test/clang-tidy/misc-misplaced-widening-cast.cpp
Index: test/clang-tidy/misc-misplaced-widening-cast.cpp
===================================================================
--- test/clang-tidy/misc-misplaced-widening-cast.cpp
+++ test/clang-tidy/misc-misplaced-widening-cast.cpp
@@ -45,8 +45,8 @@
}
void call(unsigned int n) {
+ // Don't warn about implicit casts. See
https://bugs.llvm.org/show_bug.cgi?id=32246
func(n << 8);
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: either cast from 'unsigned int'
to 'long'
func((long)(n << 8));
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: either cast from 'unsigned int'
to 'long'
func((long)n << 8);
Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp
===================================================================
--- clang-tidy/misc/MisplacedWideningCastCheck.cpp
+++ clang-tidy/misc/MisplacedWideningCastCheck.cpp
@@ -46,7 +46,7 @@
Finder->addMatcher(varDecl(hasInitializer(Cast)), this);
Finder->addMatcher(returnStmt(hasReturnValue(Cast)), this);
- Finder->addMatcher(callExpr(hasAnyArgument(Cast)), this);
+ Finder->addMatcher(callExpr(hasAnyArgument(ExplicitCast.bind("Cast"))),
this);
Finder->addMatcher(binaryOperator(hasOperatorName("="), hasRHS(Cast)), this);
Finder->addMatcher(
binaryOperator(matchers::isComparisonOperator(), hasEitherOperand(Cast)),
Index: test/clang-tidy/misc-misplaced-widening-cast.cpp
===================================================================
--- test/clang-tidy/misc-misplaced-widening-cast.cpp
+++ test/clang-tidy/misc-misplaced-widening-cast.cpp
@@ -45,8 +45,8 @@
}
void call(unsigned int n) {
+ // Don't warn about implicit casts. See https://bugs.llvm.org/show_bug.cgi?id=32246
func(n << 8);
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: either cast from 'unsigned int' to 'long'
func((long)(n << 8));
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: either cast from 'unsigned int' to 'long'
func((long)n << 8);
Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp
===================================================================
--- clang-tidy/misc/MisplacedWideningCastCheck.cpp
+++ clang-tidy/misc/MisplacedWideningCastCheck.cpp
@@ -46,7 +46,7 @@
Finder->addMatcher(varDecl(hasInitializer(Cast)), this);
Finder->addMatcher(returnStmt(hasReturnValue(Cast)), this);
- Finder->addMatcher(callExpr(hasAnyArgument(Cast)), this);
+ Finder->addMatcher(callExpr(hasAnyArgument(ExplicitCast.bind("Cast"))), this);
Finder->addMatcher(binaryOperator(hasOperatorName("="), hasRHS(Cast)), this);
Finder->addMatcher(
binaryOperator(matchers::isComparisonOperator(), hasEitherOperand(Cast)),
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits