Skip to content

Commit

Permalink
Type recognition in UseLocalizedSortingCheck
Browse files Browse the repository at this point in the history
The two checks were detecting string types in completely different ways.
Make them both behave the same way, and remove the now-unused approach.
  • Loading branch information
jbytheway committed May 7, 2020
1 parent 971d80f commit 274e82e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tools/clang-tidy-plugin/UseLocalizedSortingCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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" ),
Expand All @@ -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" ) )
) ) ) )
)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 274e82e

Please sign in to comment.