summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-03-02 15:47:28 +0000
committerAlexander Kornienko <alexfh@google.com>2017-03-02 15:47:28 +0000
commitb7f6fe46587a5f9b58b521e298f2e756a3cc6c91 (patch)
tree3af607e079759e173cb872599f3ed9ccedc9e03a
parente80d6d13604116f4c0070d34e0e880d6d31fdfaf (diff)
downloadbcm5719-llvm-b7f6fe46587a5f9b58b521e298f2e756a3cc6c91.tar.gz
bcm5719-llvm-b7f6fe46587a5f9b58b521e298f2e756a3cc6c91.zip
[clang-tidy] google-readability-casting: detect redundant casts with top-level const
llvm-svn: 296755
-rw-r--r--clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp12
-rw-r--r--clang-tools-extra/test/clang-tidy/google-readability-casting.cpp13
2 files changed, 19 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index 1c7b9428082..ae9c74e8b3d 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -75,12 +75,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
T->isMemberFunctionPointerType();
};
- const QualType DestTypeAsWritten = CastExpr->getTypeAsWritten();
- const QualType SourceTypeAsWritten = CastExpr->getSubExprAsWritten()->getType();
- const QualType SourceType =
- SourceTypeAsWritten.getCanonicalType().getUnqualifiedType();
- const QualType DestType =
- DestTypeAsWritten.getCanonicalType().getUnqualifiedType();
+ const QualType DestTypeAsWritten =
+ CastExpr->getTypeAsWritten().getUnqualifiedType();
+ const QualType SourceTypeAsWritten =
+ CastExpr->getSubExprAsWritten()->getType().getUnqualifiedType();
+ const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
+ const QualType DestType = DestTypeAsWritten.getCanonicalType();
bool FnToFnCast =
isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);
diff --git a/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp b/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
index f6c7cfb7dc5..e150c710735 100644
--- a/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
@@ -103,6 +103,19 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}}; use static_cast [
// CHECK-FIXES: Enum e = static_cast<Enum>(b1);
+ e = (Enum)Enum1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+ // CHECK-FIXES: {{^}} e = Enum1;
+
+ e = (Enum)e;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+ // CHECK-FIXES: {{^}} e = e;
+
+ static const int kZero = 0;
+ (int)kZero;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
+ // CHECK-FIXES: {{^}} kZero;
+
int b2 = int(b);
int b3 = static_cast<double>(b);
int b4 = b;
OpenPOWER on IntegriCloud