[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 14 07:17:06 PDT 2024


================
@@ -50,5 +52,32 @@ Examples:
   }
 
 The above code examples show the list of if-statements that this check will
-give a warning for. All of them uses ``compare`` to check if equality or
+give a warning for. All of them use ``compare`` to check equality or
 inequality of two strings instead of using the correct operators.
+
+Options
+-------
+
+.. option:: StringLikeClasses
+
+   A string containing comma-separated names of string-like classes. Default is an empty string.
+   If a class from this list has a ``compare`` method similar to ``std::string``, it will be checked in the same way.
+
+Example
+^^^^^^^
+
+.. code-block:: c++
+
+  struct CustomString {
+  public:
+    int compare (const CustomString& other) const;
+  }
+
+  CustomString str1;
+  CustomString str2;
+
+  // use str1 != str2 instead.
+  if (str1.compare(str2)) {
+  }
+
+If `StringLikeClasses` contains ``CustomString``, the check will suggest replacing ``compare`` with equality operator.
----------------
EugeneZelenko wrote:

What is default value?

https://github.com/llvm/llvm-project/pull/88636


More information about the cfe-commits mailing list