diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2019-06-11 10:59:22 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2019-06-11 10:59:22 +0000 |
commit | be20daa8ebcc5af8882839a5295b9069ef473dfa (patch) | |
tree | 75bc14ee5aeb64a566fa96c798198dbecc952101 | |
parent | 1a0f7a2077b70c9864faa476e15b048686cf1ca7 (diff) | |
download | bcm5719-llvm-be20daa8ebcc5af8882839a5295b9069ef473dfa.tar.gz bcm5719-llvm-be20daa8ebcc5af8882839a5295b9069ef473dfa.zip |
Fixed google-readability-casting test to work in c++17
Summary: Fixed google-readability-casting.cpp to get tests working in c++17
Reviewers: gribozavr, hokein
Reviewed By: gribozavr
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63128
Patch by Shaurya Gupta.
llvm-svn: 363047
-rw-r--r-- | clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp | 22 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/google-readability-casting.cpp | 2 |
2 files changed, 16 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp index 6a16d884e5c..3125889d191 100644 --- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp @@ -86,6 +86,10 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) { bool FnToFnCast = isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten); + const bool ConstructorCast = !CastExpr->getTypeAsWritten().hasQualifiers() && + DestTypeAsWritten->isRecordType() && + !DestTypeAsWritten->isElaboratedTypeSpecifier(); + if (CastExpr->getCastKind() == CK_NoOp && !FnToFnCast) { // Function pointer/reference casts may be needed to resolve ambiguities in // case of overloaded functions, so detection of redundant casts is trickier @@ -144,19 +148,19 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) { Diag << CastType; ReplaceWithCast((CastType + "<" + DestTypeString + ">").str()); }; - + auto ReplaceWithConstructorCall = [&]() { + Diag << "constructor call syntax"; + // FIXME: Validate DestTypeString, maybe. + ReplaceWithCast(DestTypeString.str()); + }; // Suggest appropriate C++ cast. See [expr.cast] for cast notation semantics. switch (CastExpr->getCastKind()) { case CK_FunctionToPointerDecay: ReplaceWithNamedCast("static_cast"); return; case CK_ConstructorConversion: - if (!CastExpr->getTypeAsWritten().hasQualifiers() && - DestTypeAsWritten->isRecordType() && - !DestTypeAsWritten->isElaboratedTypeSpecifier()) { - Diag << "constructor call syntax"; - // FIXME: Validate DestTypeString, maybe. - ReplaceWithCast(DestTypeString.str()); + if (ConstructorCast) { + ReplaceWithConstructorCall(); } else { ReplaceWithNamedCast("static_cast"); } @@ -176,6 +180,10 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) { ReplaceWithNamedCast("const_cast"); return; } + if (ConstructorCast) { + ReplaceWithConstructorCall(); + return; + } if (DestType->isReferenceType()) { QualType Dest = DestType.getNonReferenceType(); QualType Source = SourceType.getNonReferenceType(); 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 ffec0f89dab..4655e27cd8b 100644 --- a/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp +++ b/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy -std=c++11,c++14 %s google-readability-casting %t +// RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t // FIXME: Fix the checker to work in C++17 mode. bool g() { return false; } |