brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · faf1358 Raw
36 lines · cpp
1// RUN: %check_clang_tidy %s readability-string-compare %t -- -config='{CheckOptions: {readability-string-compare.StringLikeClasses: "CustomStringTemplateBase;CustomStringNonTemplateBase"}}' -- -isystem %clang_tidy_headers2#include <string>3 4struct CustomStringNonTemplateBase {5  int compare(const CustomStringNonTemplateBase& Other) const {6    return 123;  // value is not important for check7  }8};9 10template <typename T>11struct CustomStringTemplateBase {12  int compare(const CustomStringTemplateBase& Other) const {13    return 123;14  }15};16 17struct CustomString1 : CustomStringNonTemplateBase {};18struct CustomString2 : CustomStringTemplateBase<char> {};19 20void CustomStringClasses() {21  std::string_view sv1("a");22  std::string_view sv2("b");23  if (sv1.compare(sv2)) {  // No warning - if a std class is not listed in StringLikeClasses, it won't be checked.24  }25 26  CustomString1 custom1;27  if (custom1.compare(custom1)) {28  }29  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]30 31  CustomString2 custom2;32  if (custom2.compare(custom2)) {33  }34  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]35}36