MantisBT - Doomseeker
View Issue Details
0003817Doomseeker[All Projects] Cleanuppublic2020-06-07 06:412020-06-07 20:55
WubTheCaptain 
 
nonetweaksometimes
confirmedopen 
1.3.1 
 
0003817: std::string compare method is sometimes used instead of equality/inequality operators
I think some of these string comparisons with std::string's compare method don't make sense over equality or inequality operators (== or !=). Bad readability, clang-tidy seems to agree.
An example:
Quote from src/core/irc/ircuserinfo.cpp
bool IRCUserInfo::operator==(const IRCUserInfo &otherUser) const
{
        QString thisNickname = this->cleanNicknameLowerCase();
        QString otherNickname = otherUser.cleanNicknameLowerCase();

        return thisNickname.compare(otherNickname) == 0;
}

Could instead have written return thisNickname == otherNickname.
grep -r '\.compare' src/ | less to sort through some of these. Some Qt::CaseInsensitive cases make sense.
'https://clang.llvm.org/extra/clang-tidy/checks/readability-string-compare.html [^]'
No tags attached.
Issue History
2020-06-07 06:41WubTheCaptainNew Issue
2020-06-07 06:46WubTheCaptainNote Added: 0021367
2020-06-07 20:55Pol MNote Added: 0021391
2020-06-07 20:55Pol MStatusnew => confirmed

Notes
(0021367)
WubTheCaptain   
2020-06-07 06:46   
Technically it's QString::compare, but the same idea.
(0021391)
Pol M   
2020-06-07 20:55   
As long as there is no reason to use the result for something like a switch or something, yep, I agree.