Author: alexfh Date: Tue Jan 30 06:55:50 2018 New Revision: 323766 URL: http://llvm.org/viewvc/llvm-project?rev=323766&view=rev Log: clang-tidy/rename_check.py misc-string-compare readability-string-compare
Added: clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.cpp - copied, changed from r323765, clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.h - copied, changed from r323765, clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/readability-string-compare.rst - copied, changed from r323765, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst clang-tools-extra/trunk/test/clang-tidy/readability-string-compare.cpp - copied, changed from r323765, clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp Removed: clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=323766&r1=323765&r2=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Tue Jan 30 06:55:50 2018 @@ -17,7 +17,6 @@ add_clang_library(clangTidyMiscModule SizeofContainerCheck.cpp SizeofExpressionCheck.cpp StaticAssertCheck.cpp - StringCompareCheck.cpp StringIntegerAssignmentCheck.cpp StringLiteralWithEmbeddedNulCheck.cpp SuspiciousEnumUsageCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=323766&r1=323765&r2=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Tue Jan 30 06:55:50 2018 @@ -24,7 +24,6 @@ #include "SizeofContainerCheck.h" #include "SizeofExpressionCheck.h" #include "StaticAssertCheck.h" -#include "StringCompareCheck.h" #include "StringIntegerAssignmentCheck.h" #include "StringLiteralWithEmbeddedNulCheck.h" #include "SuspiciousEnumUsageCheck.h" @@ -75,7 +74,6 @@ public: CheckFactories.registerCheck<SizeofExpressionCheck>( "misc-sizeof-expression"); CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert"); - CheckFactories.registerCheck<StringCompareCheck>("misc-string-compare"); CheckFactories.registerCheck<StringIntegerAssignmentCheck>( "misc-string-integer-assignment"); CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>( Removed: clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp?rev=323765&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp (removed) @@ -1,82 +0,0 @@ -//===--- MiscStringCompare.cpp - clang-tidy--------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "StringCompareCheck.h" -#include "../utils/FixItHintUtils.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/Tooling/FixIt.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace misc { - -static const StringRef CompareMessage = "do not use 'compare' to test equality " - "of strings; use the string equality " - "operator instead"; - -void StringCompareCheck::registerMatchers(MatchFinder *Finder) { - if (!getLangOpts().CPlusPlus) - return; - - const auto StrCompare = cxxMemberCallExpr( - callee(cxxMethodDecl(hasName("compare"), - ofClass(classTemplateSpecializationDecl( - hasName("::std::basic_string"))))), - hasArgument(0, expr().bind("str2")), argumentCountIs(1), - callee(memberExpr().bind("str1"))); - - // First and second case: cast str.compare(str) to boolean. - Finder->addMatcher(implicitCastExpr(hasImplicitDestinationType(booleanType()), - has(StrCompare)) - .bind("match1"), - this); - - // Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0. - Finder->addMatcher( - binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")), - hasEitherOperand(StrCompare.bind("compare")), - hasEitherOperand(integerLiteral(equals(0)).bind("zero"))) - .bind("match2"), - this); -} - -void StringCompareCheck::check(const MatchFinder::MatchResult &Result) { - if (const auto *Matched = Result.Nodes.getNodeAs<Stmt>("match1")) { - diag(Matched->getLocStart(), CompareMessage); - return; - } - - if (const auto *Matched = Result.Nodes.getNodeAs<Stmt>("match2")) { - const ASTContext &Ctx = *Result.Context; - - if (const auto *Zero = Result.Nodes.getNodeAs<Stmt>("zero")) { - const auto *Str1 = Result.Nodes.getNodeAs<MemberExpr>("str1"); - const auto *Str2 = Result.Nodes.getNodeAs<Stmt>("str2"); - const auto *Compare = Result.Nodes.getNodeAs<Stmt>("compare"); - - auto Diag = diag(Matched->getLocStart(), CompareMessage); - - if (Str1->isArrow()) - Diag << FixItHint::CreateInsertion(Str1->getLocStart(), "*"); - - Diag << tooling::fixit::createReplacement(*Zero, *Str2, Ctx) - << tooling::fixit::createReplacement(*Compare, *Str1->getBase(), - Ctx); - } - } - - // FIXME: Add fixit to fix the code for case one and two (match1). -} - -} // namespace misc -} // namespace tidy -} // namespace clang Removed: clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h?rev=323765&view=auto ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h (removed) @@ -1,36 +0,0 @@ -//===--- StringCompareCheck.h - clang-tidy-----------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_COMPARE_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_COMPARE_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace misc { - -/// This check flags all calls compare when used to check for string -/// equality or inequality. -/// -/// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/misc-string-compare.html -class StringCompareCheck : public ClangTidyCheck { -public: - StringCompareCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace misc -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_COMPARE_H Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=323766&r1=323765&r2=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Tue Jan 30 06:55:50 2018 @@ -27,6 +27,7 @@ add_clang_library(clangTidyReadabilityMo SimplifyBooleanExprCheck.cpp StaticAccessedThroughInstanceCheck.cpp StaticDefinitionInAnonymousNamespaceCheck.cpp + StringCompareCheck.cpp UniqueptrDeleteReleaseCheck.cpp LINK_LIBS Modified: clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp?rev=323766&r1=323765&r2=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp Tue Jan 30 06:55:50 2018 @@ -34,6 +34,7 @@ #include "SimplifyBooleanExprCheck.h" #include "StaticAccessedThroughInstanceCheck.h" #include "StaticDefinitionInAnonymousNamespaceCheck.h" +#include "StringCompareCheck.h" #include "UniqueptrDeleteReleaseCheck.h" namespace clang { @@ -75,6 +76,8 @@ public: "readability-static-accessed-through-instance"); CheckFactories.registerCheck<StaticDefinitionInAnonymousNamespaceCheck>( "readability-static-definition-in-anonymous-namespace"); + CheckFactories.registerCheck<StringCompareCheck>( + "readability-string-compare"); CheckFactories.registerCheck<readability::NamedParameterCheck>( "readability-named-parameter"); CheckFactories.registerCheck<NonConstParameterCheck>( Copied: clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.cpp (from r323765, clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp&r1=323765&r2=323766&rev=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.cpp Tue Jan 30 06:55:50 2018 @@ -17,7 +17,7 @@ using namespace clang::ast_matchers; namespace clang { namespace tidy { -namespace misc { +namespace readability { static const StringRef CompareMessage = "do not use 'compare' to test equality " "of strings; use the string equality " @@ -77,6 +77,6 @@ void StringCompareCheck::check(const Mat // FIXME: Add fixit to fix the code for case one and two (match1). } -} // namespace misc +} // namespace readability } // namespace tidy } // namespace clang Copied: clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.h (from r323765, clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.h?p2=clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.h&p1=clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h&r1=323765&r2=323766&rev=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.h Tue Jan 30 06:55:50 2018 @@ -7,20 +7,20 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_COMPARE_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_COMPARE_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H #include "../ClangTidy.h" namespace clang { namespace tidy { -namespace misc { +namespace readability { /// This check flags all calls compare when used to check for string /// equality or inequality. /// /// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/misc-string-compare.html +/// http://clang.llvm.org/extra/clang-tidy/checks/readability-string-compare.html class StringCompareCheck : public ClangTidyCheck { public: StringCompareCheck(StringRef Name, ClangTidyContext *Context) @@ -29,8 +29,8 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; -} // namespace misc +} // namespace readability } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_STRING_COMPARE_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=323766&r1=323765&r2=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original) +++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Jan 30 06:55:50 2018 @@ -57,6 +57,9 @@ The improvements are... Improvements to clang-tidy -------------------------- +- The 'misc-string-compare' check was renamed to `readability-string-compare + <http://clang.llvm.org/extra/clang-tidy/checks/readability-string-compare.html>`_ + - New `cppcoreguidelines-avoid-goto <http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-avoid-goto.html>`_ check Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=323766&r1=323765&r2=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Tue Jan 30 06:55:50 2018 @@ -93,7 +93,7 @@ Clang-Tidy Checks google-runtime-member-string-references google-runtime-operator google-runtime-references - hicpp-avoid-goto (redirects to cppcoreguidelines-avoid-goto) <hicpp-avoid-goto> + hicpp-avoid-goto hicpp-braces-around-statements (redirects to readability-braces-around-statements) <hicpp-braces-around-statements> hicpp-deprecated-headers (redirects to modernize-deprecated-headers) <hicpp-deprecated-headers> hicpp-exception-baseclass @@ -138,7 +138,6 @@ Clang-Tidy Checks misc-sizeof-container misc-sizeof-expression misc-static-assert - misc-string-compare misc-string-integer-assignment misc-string-literal-with-embedded-nul misc-suspicious-enum-usage @@ -220,4 +219,5 @@ Clang-Tidy Checks readability-simplify-boolean-expr readability-static-accessed-through-instance readability-static-definition-in-anonymous-namespace + readability-string-compare readability-uniqueptr-delete-release Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst?rev=323765&view=auto ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst (removed) @@ -1,54 +0,0 @@ -.. title:: clang-tidy - misc-string-compare - -misc-string-compare -=================== - -Finds string comparisons using the compare method. - -A common mistake is to use the string's ``compare`` method instead of using the -equality or inequality operators. The compare method is intended for sorting -functions and thus returns a negative number, a positive number or -zero depending on the lexicographical relationship between the strings compared. -If an equality or inequality check can suffice, that is recommended. This is -recommended to avoid the risk of incorrect interpretation of the return value -and to simplify the code. The string equality and inequality operators can -also be faster than the ``compare`` method due to early termination. - -Examples: - -.. code-block:: c++ - - std::string str1{"a"}; - std::string str2{"b"}; - - // use str1 != str2 instead. - if (str1.compare(str2)) { - } - - // use str1 == str2 instead. - if (!str1.compare(str2)) { - } - - // use str1 == str2 instead. - if (str1.compare(str2) == 0) { - } - - // use str1 != str2 instead. - if (str1.compare(str2) != 0) { - } - - // use str1 == str2 instead. - if (0 == str1.compare(str2)) { - } - - // use str1 != str2 instead. - if (0 != str1.compare(str2)) { - } - - // Use str1 == "foo" instead. - if (str1.compare("foo") == 0) { - } - -The above code examples shows the list of if-statements that this check will -give a warning for. All of them uses ``compare`` to check if equality or -inequality of two strings instead of using the correct operators. Copied: clang-tools-extra/trunk/docs/clang-tidy/checks/readability-string-compare.rst (from r323765, clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-string-compare.rst?p2=clang-tools-extra/trunk/docs/clang-tidy/checks/readability-string-compare.rst&p1=clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst&r1=323765&r2=323766&rev=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/readability-string-compare.rst Tue Jan 30 06:55:50 2018 @@ -1,7 +1,7 @@ -.. title:: clang-tidy - misc-string-compare +.. title:: clang-tidy - readability-string-compare -misc-string-compare -=================== +readability-string-compare +========================== Finds string comparisons using the compare method. Removed: clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp?rev=323765&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp (removed) @@ -1,119 +0,0 @@ -// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11 - -namespace std { -template <typename T> -class allocator {}; -template <typename T> -class char_traits {}; -template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>> -class basic_string { -public: - basic_string(); - basic_string(const C *, unsigned int size); - int compare(const basic_string<char> &str) const; - int compare(const C *) const; - int compare(int, int, const basic_string<char> &str) const; - bool empty(); -}; -bool operator==(const basic_string<char> &lhs, const basic_string<char> &rhs); -bool operator!=(const basic_string<char> &lhs, const basic_string<char> &rhs); -bool operator==(const basic_string<char> &lhs, const char *&rhs); -typedef basic_string<char> string; -} - -void func(bool b); - -std::string comp() { - std::string str("a", 1); - return str; -} - -void Test() { - std::string str1("a", 1); - std::string str2("b", 1); - - if (str1.compare(str2)) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare] - if (!str1.compare(str2)) { - } - // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare] - if (str1.compare(str2) == 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str1 == str2) { - if (str1.compare(str2) != 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str1 != str2) { - if (str1.compare("foo") == 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str1 == "foo") { - if (0 == str1.compare(str2)) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str2 == str1) { - if (0 != str1.compare(str2)) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str2 != str1) { - func(str1.compare(str2)); - // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings; - if (str2.empty() || str1.compare(str2) != 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str2.empty() || str1 != str2) { - std::string *str3 = &str1; - if (str3->compare(str2)) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - if (str3->compare(str2) == 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (*str3 == str2) { - if (str2.compare(*str3) == 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str2 == *str3) { - if (comp().compare(str1) == 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (comp() == str1) { - if (str1.compare(comp()) == 0) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; - // CHECK-FIXES: if (str1 == comp()) { - if (str1.compare(comp())) { - } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; -} - -void Valid() { - std::string str1("a", 1); - std::string str2("b", 1); - if (str1 == str2) { - } - if (str1 != str2) { - } - if (str1.compare(str2) == str1.compare(str2)) { - } - if (0 == 0) { - } - if (str1.compare(str2) > 0) { - } - if (str1.compare(1, 3, str2)) { - } - if (str1.compare(str2) > 0) { - } - if (str1.compare(str2) < 0) { - } - if (str1.compare(str2) == 2) { - } - if (str1.compare(str2) == -3) { - } - if (str1.compare(str2) == 1) { - } - if (str1.compare(str2) == -1) { - } -} Copied: clang-tools-extra/trunk/test/clang-tidy/readability-string-compare.cpp (from r323765, clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp) URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-string-compare.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/readability-string-compare.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp&r1=323765&r2=323766&rev=323766&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/readability-string-compare.cpp Tue Jan 30 06:55:50 2018 @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11 +// RUN: %check_clang_tidy %s readability-string-compare %t -- -- -std=c++11 namespace std { template <typename T> @@ -34,10 +34,10 @@ void Test() { if (str1.compare(str2)) { } - // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare] + // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare] if (!str1.compare(str2)) { } - // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare] + // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare] if (str1.compare(str2) == 0) { } // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits