diff options
author | Alexander Kornienko <alexfh@google.com> | 2017-08-08 14:53:52 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2017-08-08 14:53:52 +0000 |
commit | f1a6552a95ef359317405b6b905e452c0577d22c (patch) | |
tree | af10b95774e60b52b2270e32b9b11a7e868a0145 /clang-tools-extra/clang-tidy/readability | |
parent | 64d31edef33097f3878a12285a6db4d1e9488454 (diff) | |
download | bcm5719-llvm-f1a6552a95ef359317405b6b905e452c0577d22c.tar.gz bcm5719-llvm-f1a6552a95ef359317405b6b905e452c0577d22c.zip |
[clang-tidy] 'implicit cast' -> 'implicit conversion'
Summary:
This patch renames checks, check options and changes messages to use correct
term "implicit conversion" instead of "implicit cast" (which has been in use in
Clang AST since ~10 years, but it's still technically incorrect w.r.t. C++
standard).
* performance-implicit-cast-in-loop -> performance-implicit-conversion-in-loop
* readability-implicit-bool-cast -> readability-implicit-bool-conversion
- readability-implicit-bool-cast.AllowConditionalIntegerCasts ->
readability-implicit-bool-conversion.AllowIntegerConditions
- readability-implicit-bool-cast.AllowConditionalPointerCasts ->
readability-implicit-bool-conversion.AllowPointerConditions
Reviewers: hokein, jdennett
Reviewed By: hokein
Subscribers: mgorny, JDevlieghere, xazax.hun, cfe-commits
Differential Revision: https://reviews.llvm.org/D36456
llvm-svn: 310366
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/CMakeLists.txt | 2 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp (renamed from clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp) | 54 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h (renamed from clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.h) | 20 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp | 6 |
4 files changed, 40 insertions, 42 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt index bed728731ed..8e6c6581735 100644 --- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt @@ -9,7 +9,7 @@ add_clang_library(clangTidyReadabilityModule ElseAfterReturnCheck.cpp FunctionSizeCheck.cpp IdentifierNamingCheck.cpp - ImplicitBoolCastCheck.cpp + ImplicitBoolConversionCheck.cpp InconsistentDeclarationParameterNameCheck.cpp MisleadingIndentationCheck.cpp MisplacedArrayIndexCheck.cpp diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index 996219c8bd8..79022d4259a 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -1,4 +1,4 @@ -//===--- ImplicitBoolCastCheck.cpp - clang-tidy----------------------------===// +//===--- ImplicitBoolConversionCheck.cpp - clang-tidy----------------------===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "ImplicitBoolCastCheck.h" +#include "ImplicitBoolConversionCheck.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" @@ -218,7 +218,7 @@ StringRef getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral, return BoolLiteral->getValue() ? "1" : "0"; } -bool isAllowedConditionalCast(const ImplicitCastExpr *Cast, +bool isCastAllowedInCondition(const ImplicitCastExpr *Cast, ASTContext &Context) { std::queue<const Stmt *> Q; Q.push(Cast); @@ -245,22 +245,19 @@ bool isAllowedConditionalCast(const ImplicitCastExpr *Cast, } // anonymous namespace -ImplicitBoolCastCheck::ImplicitBoolCastCheck(StringRef Name, - ClangTidyContext *Context) +ImplicitBoolConversionCheck::ImplicitBoolConversionCheck( + StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - AllowConditionalIntegerCasts( - Options.get("AllowConditionalIntegerCasts", false)), - AllowConditionalPointerCasts( - Options.get("AllowConditionalPointerCasts", false)) {} - -void ImplicitBoolCastCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "AllowConditionalIntegerCasts", - AllowConditionalIntegerCasts); - Options.store(Opts, "AllowConditionalPointerCasts", - AllowConditionalPointerCasts); + AllowIntegerConditions(Options.get("AllowIntegerConditions", false)), + AllowPointerConditions(Options.get("AllowPointerConditions", false)) {} + +void ImplicitBoolConversionCheck::storeOptions( + ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions); + Options.store(Opts, "AllowPointerConditions", AllowPointerConditions); } -void ImplicitBoolCastCheck::registerMatchers(MatchFinder *Finder) { +void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { // This check doesn't make much sense if we run it on language without // built-in bool support. if (!getLangOpts().Bool) { @@ -326,7 +323,8 @@ void ImplicitBoolCastCheck::registerMatchers(MatchFinder *Finder) { this); } -void ImplicitBoolCastCheck::check(const MatchFinder::MatchResult &Result) { +void ImplicitBoolConversionCheck::check( + const MatchFinder::MatchResult &Result) { if (const auto *CastToBool = Result.Nodes.getNodeAs<ImplicitCastExpr>("implicitCastToBool")) { const auto *Parent = Result.Nodes.getNodeAs<Stmt>("parentStmt"); @@ -341,23 +339,22 @@ void ImplicitBoolCastCheck::check(const MatchFinder::MatchResult &Result) { } } -void ImplicitBoolCastCheck::handleCastToBool(const ImplicitCastExpr *Cast, - const Stmt *Parent, - ASTContext &Context) { - if (AllowConditionalPointerCasts && +void ImplicitBoolConversionCheck::handleCastToBool(const ImplicitCastExpr *Cast, + const Stmt *Parent, + ASTContext &Context) { + if (AllowPointerConditions && (Cast->getCastKind() == CK_PointerToBoolean || Cast->getCastKind() == CK_MemberPointerToBoolean) && - isAllowedConditionalCast(Cast, Context)) { + isCastAllowedInCondition(Cast, Context)) { return; } - if (AllowConditionalIntegerCasts && - Cast->getCastKind() == CK_IntegralToBoolean && - isAllowedConditionalCast(Cast, Context)) { + if (AllowIntegerConditions && Cast->getCastKind() == CK_IntegralToBoolean && + isCastAllowedInCondition(Cast, Context)) { return; } - auto Diag = diag(Cast->getLocStart(), "implicit cast %0 -> bool") + auto Diag = diag(Cast->getLocStart(), "implicit conversion %0 -> bool") << Cast->getSubExpr()->getType(); StringRef EquivalentLiteral = @@ -369,12 +366,13 @@ void ImplicitBoolCastCheck::handleCastToBool(const ImplicitCastExpr *Cast, } } -void ImplicitBoolCastCheck::handleCastFromBool( +void ImplicitBoolConversionCheck::handleCastFromBool( const ImplicitCastExpr *Cast, const ImplicitCastExpr *NextImplicitCast, ASTContext &Context) { QualType DestType = NextImplicitCast ? NextImplicitCast->getType() : Cast->getType(); - auto Diag = diag(Cast->getLocStart(), "implicit cast bool -> %0") << DestType; + auto Diag = diag(Cast->getLocStart(), "implicit conversion bool -> %0") + << DestType; if (const auto *BoolLiteral = dyn_cast<CXXBoolLiteralExpr>(Cast->getSubExpr())) { diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.h b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h index cd8addfde64..bb062e02e05 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.h +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h @@ -1,4 +1,4 @@ -//===--- ImplicitBoolCastCheck.h - clang-tidy--------------------*- C++ -*-===// +//===--- ImplicitBoolConversionCheck.h - clang-tidy--------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CAST_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CAST_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CONVERSION_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CONVERSION_H #include "../ClangTidy.h" @@ -16,13 +16,13 @@ namespace clang { namespace tidy { namespace readability { -/// \brief Checks for use of implicit bool casts in expressions. +/// \brief Checks for use of implicit bool conversions in expressions. /// /// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-cast.html -class ImplicitBoolCastCheck : public ClangTidyCheck { +/// http://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-conversion.html +class ImplicitBoolConversionCheck : public ClangTidyCheck { public: - ImplicitBoolCastCheck(StringRef Name, ClangTidyContext *Context); + ImplicitBoolConversionCheck(StringRef Name, ClangTidyContext *Context); void storeOptions(ClangTidyOptions::OptionMap &Opts) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; @@ -35,12 +35,12 @@ private: const ImplicitCastExpr *FurtherImplicitCastExpression, ASTContext &Context); - bool AllowConditionalIntegerCasts; - bool AllowConditionalPointerCasts; + const bool AllowIntegerConditions; + const bool AllowPointerConditions; }; } // namespace readability } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CAST_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IMPLICIT_BOOL_CONVERSION_H diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp index dacea0d1e4d..81a9d6f3d00 100644 --- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp @@ -18,7 +18,7 @@ #include "ElseAfterReturnCheck.h" #include "FunctionSizeCheck.h" #include "IdentifierNamingCheck.h" -#include "ImplicitBoolCastCheck.h" +#include "ImplicitBoolConversionCheck.h" #include "InconsistentDeclarationParameterNameCheck.h" #include "MisleadingIndentationCheck.h" #include "MisplacedArrayIndexCheck.h" @@ -58,8 +58,8 @@ public: "readability-function-size"); CheckFactories.registerCheck<IdentifierNamingCheck>( "readability-identifier-naming"); - CheckFactories.registerCheck<ImplicitBoolCastCheck>( - "readability-implicit-bool-cast"); + CheckFactories.registerCheck<ImplicitBoolConversionCheck>( + "readability-implicit-bool-conversion"); CheckFactories.registerCheck<InconsistentDeclarationParameterNameCheck>( "readability-inconsistent-declaration-parameter-name"); CheckFactories.registerCheck<MisleadingIndentationCheck>( |