nicovank wrote:
FYI I'm going to merge #110386 now which will cause conflicts (`binaryOperator`
-> `binaryOperation`).
https://github.com/llvm/llvm-project/pull/110351
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-
nicovank wrote:
Thanks!
Is there still an issue with type stuff? If so, what would be a test case that
fails that shouldn't?
https://github.com/llvm/llvm-project/pull/110351
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.or
@@ -29,6 +29,43 @@ struct multimap {
bool contains(const Key &K) const;
};
+using size_t = decltype(sizeof(int));
+
+// Lightweight standin for std::string_view.
+template
+class basic_string_view {
+public:
+ basic_string_view();
+ basic_string_view(const basic_string_vi
@@ -32,7 +33,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
const auto FindCall =
cxxMemberCallExpr(
- argumentCountIs(1),
+ anyOf(argumentCountIs(1),
+allOf(argumentCountIs(2), hasArgument(1,
cxxDefaultArg
@@ -453,3 +458,29 @@ void testOperandPermutations(std::map& Map) {
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check
for membership [readability-container-contains]
// CHECK-FIXES: if (!Map.contains(0)) {};
}
+
+void testStringNops(std::string St
@@ -50,12 +50,16 @@ struct basic_string {
size_type find(const _Type& str, size_type pos = 0) const;
size_type find(const C* s, size_type pos = 0) const;
size_type find(const C* s, size_type pos, size_type n) const;
+ size_type find(C ch, size_type pos = 0) const;
s
@@ -30,9 +32,15 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
ofClass(cxxRecordDecl(HasContainsMatchingParamType)
.bind("call");
+ const auto Literal0 = integerLiteral(equals(0));
+ const auto Literal1 = integerLiteral(e
@@ -50,12 +50,16 @@ struct basic_string {
size_type find(const _Type& str, size_type pos = 0) const;
size_type find(const C* s, size_type pos = 0) const;
size_type find(const C* s, size_type pos, size_type n) const;
+ size_type find(C ch, size_type pos = 0) const;
--
@@ -104,6 +108,9 @@ struct basic_string_view {
size_type rfind(const C* s, size_type pos, size_type count) const;
size_type rfind(const C* s, size_type pos = npos) const;
+ bool contains(const C *s) const;
+ bool contains(C s) const;
nicovank wrote:
```
@@ -32,7 +33,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
const auto FindCall =
cxxMemberCallExpr(
- argumentCountIs(1),
+ anyOf(argumentCountIs(1),
+allOf(argumentCountIs(2), hasArgument(1,
cxxDefaultArg
@@ -453,3 +490,15 @@ void testOperandPermutations(std::map& Map) {
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check
for membership [readability-container-contains]
// CHECK-FIXES: if (!Map.contains(0)) {};
}
+
+void testStringNops(std::string St
@@ -29,6 +29,43 @@ struct multimap {
bool contains(const Key &K) const;
};
+using size_t = decltype(sizeof(int));
+
+// Lightweight standin for std::string_view.
+template
+class basic_string_view {
+public:
+ basic_string_view();
+ basic_string_view(const basic_string_vi
@@ -94,12 +102,14 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
binaryOperator(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
.bind("negativeComparison"));
- // Find membership tests based on `find() == end()`.
+ // Find
@@ -51,6 +53,12 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
const auto Literal0 = integerLiteral(equals(0));
const auto Literal1 = integerLiteral(equals(1));
+ const auto StringLikeClass = cxxRecordDecl(
+ hasAnyName("::std::basic_string"
https://github.com/dl8sd11 updated
https://github.com/llvm/llvm-project/pull/110351
>From b98e9a4d50d74c298096d2bd2d70ff4c0ef5c4a4 Mon Sep 17 00:00:00 2001
From: dl8sd11
Date: Sat, 28 Sep 2024 07:37:50 +
Subject: [PATCH 1/5] [clang-tidy] support string::contains
---
.../readability/Contai
https://github.com/dl8sd11 updated
https://github.com/llvm/llvm-project/pull/110351
>From b98e9a4d50d74c298096d2bd2d70ff4c0ef5c4a4 Mon Sep 17 00:00:00 2001
From: dl8sd11
Date: Sat, 28 Sep 2024 07:37:50 +
Subject: [PATCH 1/4] [clang-tidy] support string::contains
---
.../readability/Contai
@@ -94,12 +102,14 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
binaryOperator(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
.bind("negativeComparison"));
- // Find membership tests based on `find() == end()`.
+ // Find
@@ -453,3 +490,15 @@ void testOperandPermutations(std::map& Map) {
// CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check
for membership [readability-container-contains]
// CHECK-FIXES: if (!Map.contains(0)) {};
}
+
+void testStringNops(std::string St
@@ -29,6 +29,43 @@ struct multimap {
bool contains(const Key &K) const;
};
+using size_t = decltype(sizeof(int));
+
+// Lightweight standin for std::string_view.
+template
+class basic_string_view {
+public:
+ basic_string_view();
+ basic_string_view(const basic_string_vi
@@ -51,6 +53,12 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
const auto Literal0 = integerLiteral(equals(0));
const auto Literal1 = integerLiteral(equals(1));
+ const auto StringLikeClass = cxxRecordDecl(
+ hasAnyName("::std::basic_string"
https://github.com/nicovank commented:
IMO no need to update release notes:
> Improved `readability-container-contains` check to let it work on any class
> that has a contains method.
But I think an example should be added to [the check
documentation](https://github.com/llvm/llvm-project/blob
@@ -32,7 +33,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder
*Finder) {
const auto FindCall =
cxxMemberCallExpr(
- argumentCountIs(1),
+ anyOf(argumentCountIs(1),
+allOf(argumentCountIs(2), hasArgument(1,
cxxDefaultArg
https://github.com/nicovank edited
https://github.com/llvm/llvm-project/pull/110351
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
github-actions[bot] wrote:
Thank you for submitting a Pull Request (PR) to the LLVM Project!
This PR will be automatically labeled and the relevant teams will be notified.
If you wish to, you can add reviewers by using the "Reviewers" section on this
page.
If this is not working for you, it
https://github.com/dl8sd11 created
https://github.com/llvm/llvm-project/pull/110351
Starting from c++23, we can replace `std::string::find() == std::string::npos`
with `std::string.contains()` . #109327
Currently, this is WIP because there are two limitations:
1. False positive: SubStr type i
25 matches
Mail list logo