brintos

brintos / llvm-project-archived public Read only

0
0
Text · 20.4 KiB · 1d848ab Raw
495 lines · cpp
1// RUN: %check_clang_tidy %s readability-container-contains %t -- \2// RUN:   -- -isystem %clang_tidy_headers3 4#include <string>5 6// Some *very* simplified versions of `map` etc.7namespace std {8 9template <class Key, class T>10struct map {11  struct iterator {12    bool operator==(const iterator &Other) const;13    bool operator!=(const iterator &Other) const;14  };15 16  unsigned count(const Key &K) const;17  bool contains(const Key &K) const;18  iterator find(const Key &K);19  iterator end();20};21 22template <class Key>23struct set {24  unsigned count(const Key &K) const;25  bool contains(const Key &K) const;26};27 28template <class Key>29struct unordered_set {30  unsigned count(const Key &K) const;31  bool contains(const Key &K) const;32};33 34template <class Key, class T>35struct multimap {36  unsigned count(const Key &K) const;37  bool contains(const Key &K) const;38};39 40} // namespace std41 42// Check that we detect various common ways to check for membership43int testDifferentCheckTypes(std::map<int, int> &MyMap) {44  if (MyMap.count(0))45    // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use 'contains' to check for membership [readability-container-contains]46    // CHECK-FIXES: if (MyMap.contains(0))47    return 1;48  bool C1 = MyMap.count(1);49  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]50  // CHECK-FIXES: bool C1 = MyMap.contains(1);51  auto C2 = static_cast<bool>(MyMap.count(1));52  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: use 'contains' to check for membership [readability-container-contains]53  // CHECK-FIXES: auto C2 = static_cast<bool>(MyMap.contains(1));54  auto C3 = MyMap.count(2) != 0;55  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]56  // CHECK-FIXES: auto C3 = MyMap.contains(2);57  auto C4 = MyMap.count(3) > 0;58  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]59  // CHECK-FIXES: auto C4 = MyMap.contains(3);60  auto C5 = MyMap.count(4) >= 1;61  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]62  // CHECK-FIXES: auto C5 = MyMap.contains(4);63  auto C6 = MyMap.find(5) != MyMap.end();64  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]65  // CHECK-FIXES: auto C6 = MyMap.contains(5);66  return C1 + C2 + C3 + C4 + C5 + C6;67}68 69// Check that we detect various common ways to check for non-membership70int testNegativeChecks(std::map<int, int> &MyMap) {71  bool C1 = !MyMap.count(-1);72  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use 'contains' to check for membership [readability-container-contains]73  // CHECK-FIXES: bool C1 = !MyMap.contains(-1);74  auto C2 = MyMap.count(-2) == 0;75  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]76  // CHECK-FIXES: auto C2 = !MyMap.contains(-2);77  auto C3 = MyMap.count(-3) <= 0;78  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]79  // CHECK-FIXES: auto C3 = !MyMap.contains(-3);80  auto C4 = MyMap.count(-4) < 1;81  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]82  // CHECK-FIXES: auto C4 = !MyMap.contains(-4);83  auto C5 = MyMap.find(-5) == MyMap.end();84  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]85  // CHECK-FIXES: auto C5 = !MyMap.contains(-5);86  return C1 + C2 + C3 + C4 + C5;87}88 89// Check for various types90int testDifferentTypes(std::map<int, int> &M, std::unordered_set<int> &US, std::set<int> &S, std::multimap<int, int> &MM) {91  bool C1 = M.count(1001);92  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use 'contains' to check for membership [readability-container-contains]93  // CHECK-FIXES: bool C1 = M.contains(1001);94  bool C2 = US.count(1002);95  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use 'contains' to check for membership [readability-container-contains]96  // CHECK-FIXES: bool C2 = US.contains(1002);97  bool C3 = S.count(1003);98  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use 'contains' to check for membership [readability-container-contains]99  // CHECK-FIXES: bool C3 = S.contains(1003);100  bool C4 = MM.count(1004);101  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use 'contains' to check for membership [readability-container-contains]102  // CHECK-FIXES: bool C4 = MM.contains(1004);103  return C1 + C2 + C3 + C4;104}105 106// The check detects all kind of `const`, reference, rvalue-reference and value types.107int testQualifiedTypes(std::map<int, int> ValueM, std::map<int, int> &RefM, const std::map<int, int> &ConstRefM, std::map<int, int> &&RValueM) {108  bool C1 = ValueM.count(2001);109  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use 'contains' to check for membership [readability-container-contains]110  // CHECK-FIXES: bool C1 = ValueM.contains(2001);111  bool C2 = RefM.count(2002);112  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use 'contains' to check for membership [readability-container-contains]113  // CHECK-FIXES: bool C2 = RefM.contains(2002);114  bool C3 = ConstRefM.count(2003);115  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use 'contains' to check for membership [readability-container-contains]116  // CHECK-FIXES: bool C3 = ConstRefM.contains(2003);117  bool C4 = RValueM.count(2004);118  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use 'contains' to check for membership [readability-container-contains]119  // CHECK-FIXES: bool C4 = RValueM.contains(2004);120  return C1 + C2 + C3 + C4;121}122 123// This is effectively a membership check, as the result is implicitly casted124// to `bool`.125bool returnContains(std::map<int, int> &M) {126  return M.count(42);127  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use 'contains' to check for membership [readability-container-contains]128  // CHECK-FIXES: return M.contains(42);129}130 131// This returns the actual count and should not be rewritten132int actualCount(std::multimap<int, int> &M) {133  return M.count(21);134  // NO-WARNING.135  // CHECK-FIXES: return M.count(21);136}137 138// Check that we are not confused by aliases139namespace s2 = std;140using MyMapT = s2::map<int, int>;141int typeAliases(MyMapT &MyMap) {142  bool C1 = MyMap.count(99);143  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]144  // CHECK-FIXES: bool C1 = MyMap.contains(99);145  return C1;146}147 148// Check that the tests also trigger for a local variable and not only for149// function arguments.150bool localVar() {151  using namespace std;152  map<int, int> LocalM;153  return LocalM.count(42);154  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use 'contains' to check for membership [readability-container-contains]155  // CHECK-FIXES: return LocalM.contains(42);156}157 158// Check various usages of an actual `count` which isn't rewritten159int nonRewrittenCount(std::multimap<int, int> &MyMap) {160  // This is an actual test if we have at least 2 usages. Shouldn't be rewritten.161  bool C1 = MyMap.count(1) >= 2;162  // NO-WARNING.163  // CHECK-FIXES: bool C1 = MyMap.count(1) >= 2;164 165  // "< 0" makes little sense and is always `false`. Still, let's ensure we166  // don't accidentally rewrite it to 'contains'.167  bool C2 = MyMap.count(2) < 0;168  // NO-WARNING.169  // CHECK-FIXES: bool C2 = MyMap.count(2) < 0;170 171  // The `count` is used in some more complicated formula.172  bool C3 = MyMap.count(1) + MyMap.count(2) * 2 + MyMap.count(3) / 3 >= 20;173  // NO-WARNING.174  // CHECK-FIXES: bool C3 = MyMap.count(1) + MyMap.count(2) * 2 + MyMap.count(3) / 3 >= 20;175 176  // This could theoretically be rewritten into a 'contains' after removig the177  // `4` on both sides of the comparison. For the time being, we don't detect178  // this case.179  bool C4 = MyMap.count(1) + 4 > 4;180  // NO-WARNING.181  // CHECK-FIXES: bool C4 = MyMap.count(1) + 4 > 4;182 183  return C1 + C2 + C3 + C4;184}185 186// Check different integer literal suffixes187int testDifferentIntegerLiteralSuffixes(std::map<int, int> &MyMap) {188 189  auto C1 = MyMap.count(2) != 0U;190  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]191  // CHECK-FIXES: auto C1 = MyMap.contains(2);192  auto C2 = MyMap.count(2) != 0UL;193  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]194  // CHECK-FIXES: auto C2 = MyMap.contains(2);195  auto C3 = 0U != MyMap.count(2);196  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use 'contains' to check for membership [readability-container-contains]197  // CHECK-FIXES: auto C3 = MyMap.contains(2);198  auto C4 = 0UL != MyMap.count(2);199  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use 'contains' to check for membership [readability-container-contains]200  // CHECK-FIXES: auto C4 = MyMap.contains(2);201  auto C5 = MyMap.count(2) < 1U;202  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]203  // CHECK-FIXES: auto C5 = !MyMap.contains(2);204  auto C6 = MyMap.count(2) < 1UL;205  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]206  // CHECK-FIXES: auto C6 = !MyMap.contains(2);207  auto C7 = 1U > MyMap.count(2);208  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use 'contains' to check for membership [readability-container-contains]209  // CHECK-FIXES: auto C7 = !MyMap.contains(2);210  auto C8 = 1UL > MyMap.count(2);211  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use 'contains' to check for membership [readability-container-contains]212  // CHECK-FIXES: auto C8 = !MyMap.contains(2);213 214  return C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8;215}216 217// We don't want to rewrite if the `contains` call is from a macro expansion218int testMacroExpansion(std::unordered_set<int> &MySet) {219#define COUNT_ONES(SET) SET.count(1)220  // Rewriting the macro would break the code221  // CHECK-FIXES: #define COUNT_ONES(SET) SET.count(1)222  // We still want to warn the user even if we don't offer a fixit223  if (COUNT_ONES(MySet)) {224    // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use 'contains' to check for membership [readability-container-contains]225    // CHECK-MESSAGES: note: expanded from macro 'COUNT_ONES'226    return COUNT_ONES(MySet);227  }228#undef COUNT_ONES229#define COUNT_ONES count(1)230  // Rewriting the macro would break the code231  // CHECK-FIXES: #define COUNT_ONES count(1)232  // We still want to warn the user even if we don't offer a fixit233  if (MySet.COUNT_ONES) {234    // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use 'contains' to check for membership [readability-container-contains]235    // CHECK-MESSAGES: note: expanded from macro 'COUNT_ONES'236    return MySet.COUNT_ONES;237  }238#undef COUNT_ONES239#define MY_SET MySet240  // CHECK-FIXES: #define MY_SET MySet241  // We still want to rewrite one of the two calls to `count`242  if (MY_SET.count(1)) {243    // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use 'contains' to check for membership [readability-container-contains]244    // CHECK-FIXES: if (MY_SET.contains(1)) {245    return MY_SET.count(1);246  }247#undef MY_SET248  return 0;249}250 251// The following map has the same interface as `std::map`.252template <class Key, class T>253struct CustomMap {254  unsigned count(const Key &K) const;255  bool contains(const Key &K) const;256  void *find(const Key &K);257  void *end();258};259 260void testDifferentCheckTypes(CustomMap<int, int> &MyMap) {261  if (MyMap.count(0)) {}262  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]263  // CHECK-FIXES: if (MyMap.contains(0)) {}264 265  MyMap.find(0) != MyMap.end();266  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]267  // CHECK-FIXES: MyMap.contains(0);268}269 270struct MySubmap : public CustomMap<int, int> {};271 272void testSubclass(MySubmap& MyMap) {273  if (MyMap.count(0)) {}274  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]275  // CHECK-FIXES: if (MyMap.contains(0)) {}276}277 278using UsingMap = CustomMap<int, int>;279struct MySubmap2 : public UsingMap {};280using UsingMap2 = MySubmap2;281 282void testUsing(UsingMap2& MyMap) {283  if (MyMap.count(0)) {}284  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]285  // CHECK-FIXES: if (MyMap.contains(0)) {}286}287 288template <class Key, class T>289struct CustomMapContainsDeleted {290  unsigned count(const Key &K) const;291  bool contains(const Key &K) const = delete;292  void *find(const Key &K);293  void *end();294};295 296struct SubmapContainsDeleted : public CustomMapContainsDeleted<int, int> {};297 298void testContainsDeleted(CustomMapContainsDeleted<int, int> &MyMap,299                         SubmapContainsDeleted &MyMap2) {300  // No warning if the `contains` method is deleted.301  if (MyMap.count(0)) {}302  if (MyMap2.count(0)) {}303}304 305template <class Key, class T>306struct CustomMapPrivateContains {307  unsigned count(const Key &K) const;308  void *find(const Key &K);309  void *end();310 311private:312  bool contains(const Key &K) const;313};314 315struct SubmapPrivateContains : public CustomMapPrivateContains<int, int> {};316 317void testPrivateContains(CustomMapPrivateContains<int, int> &MyMap,318                         SubmapPrivateContains &MyMap2) {319  // No warning if the `contains` method is not public.320  if (MyMap.count(0)) {}321  if (MyMap2.count(0)) {}322}323 324struct WeirdNonMatchingContains {325  unsigned count(char) const;326  bool contains(const std::string&) const;327};328 329// False positives: when count/find and contains take different types,330// the check will suggest an invalid code transformation. These cases331// should not exist in real code or be rare enough.332void f(WeirdNonMatchingContains MyMap) {333  if (MyMap.count('a')) {}334  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]335  // CHECK-FIXES: if (MyMap.contains('a')) {}336}337 338template <class T>339struct SmallPtrSet {340  using ConstPtrType = const T*;341  unsigned count(ConstPtrType Ptr) const;342  bool contains(ConstPtrType Ptr) const;343};344 345template <class T>346struct SmallPtrPtrSet {347  using ConstPtrType = const T**;348  unsigned count(ConstPtrType Ptr) const;349  bool contains(ConstPtrType Ptr) const;350};351 352template <class T>353struct SmallPtrPtrPtrSet {354  using ConstPtrType = const T***;355  unsigned count(ConstPtrType Ptr) const;356  bool contains(ConstPtrType Ptr) const;357};358 359void testSmallPtrSet(const int ***Ptr,360                     SmallPtrSet<int> &MySet,361                     SmallPtrPtrSet<int> &MySet2,362                     SmallPtrPtrPtrSet<int> &MySet3) {363  if (MySet.count(**Ptr)) {}364  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]365  // CHECK-FIXES: if (MySet.contains(**Ptr)) {}366  if (MySet2.count(*Ptr)) {}367  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]368  // CHECK-FIXES: if (MySet2.contains(*Ptr)) {}369  if (MySet3.count(Ptr)) {}370  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]371  // CHECK-FIXES: if (MySet3.contains(Ptr)) {}372}373 374struct X {};375struct Y : public X {};376 377void testSubclassEntry(SmallPtrSet<X>& Set, Y* Entry) {378  if (Set.count(Entry)) {}379  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]380  // CHECK-FIXES: if (Set.contains(Entry)) {}381}382 383void testIntUnsigned(std::set<int>& S, unsigned U) {384  if (S.count(U)) {}385  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]386  // CHECK-FIXES: if (S.contains(U)) {}387}388 389template <class T>390struct CustomSetConvertible {391  unsigned count(const T &K) const;392  bool contains(const T &K) const;393};394 395struct A {};396struct B { B() = default; B(const A&) {} };397struct C { operator A() const; };398 399void testConvertibleTypes() {400  CustomSetConvertible<B> MyMap;401  if (MyMap.count(A())) {}402  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]403  // CHECK-FIXES: if (MyMap.contains(A())) {}404 405  CustomSetConvertible<A> MyMap2;406  if (MyMap2.count(C())) {}407  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]408  // CHECK-FIXES: if (MyMap2.contains(C())) {}409 410  if (MyMap2.count(C()) != 0) {}411  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]412  // CHECK-FIXES: if (MyMap2.contains(C())) {}413}414 415template<class U>416using Box = const U& ;417 418template <class T>419struct CustomBoxedSet {420  unsigned count(Box<T> K) const;421  bool contains(Box<T> K) const;422};423 424void testBox() {425  CustomBoxedSet<int> Set;426  if (Set.count(0)) {}427  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]428  // CHECK-FIXES: if (Set.contains(0)) {}429}430 431void testOperandPermutations(std::map<int, int>& Map) {432  if (Map.count(0) != 0) {}433  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]434  // CHECK-FIXES: if (Map.contains(0)) {}435  if (0 != Map.count(0)) {}436  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]437  // CHECK-FIXES: if (Map.contains(0)) {}438  if (Map.count(0) == 0) {}439  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]440  // CHECK-FIXES: if (!Map.contains(0)) {}441  if (0 == Map.count(0)) {}442  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]443  // CHECK-FIXES: if (!Map.contains(0)) {}444  if (Map.find(0) != Map.end()) {}445  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]446  // CHECK-FIXES: if (Map.contains(0)) {}447  if (Map.end() != Map.find(0)) {}448  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]449  // CHECK-FIXES: if (Map.contains(0)) {}450  if (Map.find(0) == Map.end()) {}451  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]452  // CHECK-FIXES: if (!Map.contains(0)) {}453  if (Map.end() == Map.find(0)) {}454  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]455  // CHECK-FIXES: if (!Map.contains(0)) {}456}457 458void testStringNpos(std::string Str1, std::string Str2, std::string_view StrView) {459  if (Str1.find(Str2) == std::string::npos) {}460  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]461  // CHECK-FIXES: if (!Str1.contains(Str2)) {}462 463  if (Str1.find("test") == std::string::npos) {}464  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]465  // CHECK-FIXES: if (!Str1.contains("test")) {}466 467  if (Str1.find('c') != std::string::npos) {}468  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]469  // CHECK-FIXES: if (Str1.contains('c')) {}470 471  if (Str1.find(Str2, 0) != std::string::npos) {}472  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]473  // CHECK-FIXES: if (Str1.contains(Str2)) {}474 475  if (std::string::npos == Str1.find("test", 0)) {}476  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]477  // CHECK-FIXES: if (!Str1.contains("test")) {}478 479  if (StrView.find("test") == std::string_view::npos) {}480  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]481  // CHECK-FIXES: if (!StrView.contains("test")) {}482 483  if (StrView.find('c') != std::string_view::npos) {}484  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]485  // CHECK-FIXES: if (StrView.contains('c')) {}486 487  if (StrView.find('c') != StrView.npos) {}488  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check for membership [readability-container-contains]489  // CHECK-FIXES: if (StrView.contains('c')) {}490 491  // These should not match.492  if (Str1.find('c', 1) != Str1.npos) {}493  if (Str1.find(StrView, 1) != Str1.npos) {}494}495