Author: gribozavr Date: Tue Jun 11 03:59:22 2019 New Revision: 363047 URL: http://llvm.org/viewvc/llvm-project?rev=363047&view=rev Log: 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. Modified: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp Modified: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp?rev=363047&r1=363046&r2=363047&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp Tue Jun 11 03:59:22 2019 @@ -86,6 +86,10 @@ void AvoidCStyleCastsCheck::check(const 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 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 ReplaceWithNamedCast("const_cast"); return; } + if (ConstructorCast) { + ReplaceWithConstructorCall(); + return; + } if (DestType->isReferenceType()) { QualType Dest = DestType.getNonReferenceType(); QualType Source = SourceType.getNonReferenceType(); Modified: clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp?rev=363047&r1=363046&r2=363047&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp Tue Jun 11 03:59:22 2019 @@ -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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits