From 274e82e73132cbe3ddc1d1e149302c84bef8481a Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Mon, 4 May 2020 20:01:45 -0400 Subject: [PATCH] Type recognition in UseLocalizedSortingCheck The two checks were detecting string types in completely different ways. Make them both behave the same way, and remove the now-unused approach. --- .../UseLocalizedSortingCheck.cpp | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/clang-tidy-plugin/UseLocalizedSortingCheck.cpp b/tools/clang-tidy-plugin/UseLocalizedSortingCheck.cpp index f7ea445e49382..e72a15d672cbc 100644 --- a/tools/clang-tidy-plugin/UseLocalizedSortingCheck.cpp +++ b/tools/clang-tidy-plugin/UseLocalizedSortingCheck.cpp @@ -33,11 +33,6 @@ namespace tidy namespace cata { -inline auto isStringType() -{ - return qualType( anyOf( asString( "const std::string" ), asString( "std::string" ) ) ); -} - inline bool IsString( QualType T ) { const TagDecl *TTag = T.getTypePtr()->getAsTagDecl(); @@ -54,7 +49,7 @@ void UseLocalizedSortingCheck::registerMatchers( MatchFinder *Finder ) cxxOperatorCallExpr( hasArgument( 0, - expr( hasType( isStringType().bind( "arg0Type" ) ) ).bind( "arg0Expr" ) + expr( hasType( qualType().bind( "arg0Type" ) ) ).bind( "arg0Expr" ) ), hasOverloadedOperatorName( "<" ) ).bind( "opCall" ), @@ -68,7 +63,7 @@ void UseLocalizedSortingCheck::registerMatchers( MatchFinder *Finder ) hasArgument( 0, expr( hasType( qualType( anyOf( - pointerType( pointee( isStringType().bind( "valueType" ) ) ), + pointerType( pointee( qualType().bind( "valueType" ) ) ), hasDeclaration( decl().bind( "iteratorDecl" ) ) ) ) ) ) ) @@ -86,6 +81,10 @@ static void CheckOpCall( UseLocalizedSortingCheck &Check, const MatchFinder::Mat return; } + if( !IsString( *Arg0Type ) ) { + return; + } + StringRef Arg0Text = getText( Result, Arg0Expr ); if( Arg0Text.endswith( "id" ) ) { return; @@ -118,16 +117,16 @@ static void CheckSortCall( UseLocalizedSortingCheck &Check, const MatchFinder::M } } } - - if( !IsString( ValueType ) ) { - return; - } } if( BoundValueType ) { ValueType = *BoundValueType; } + if( !IsString( ValueType ) ) { + return; + } + Check.diag( Call->getBeginLoc(), "Raw sort of %0. For UI purposes please use localized_compare from " "translations.h." ) << ValueType;