Skip to content

Commit 0dd8f6f

Browse files
committed
[ClangTidy] NFC: Add more tests for container-size-empty
1 parent 702f822 commit 0dd8f6f

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ std::string s_func() {
100100
return std::string();
101101
}
102102

103-
int main() {
103+
void takesBool(bool)
104+
{
105+
106+
}
107+
108+
bool returnsBool() {
104109
std::set<int> intSet;
105110
std::string str;
106111
std::string str2;
@@ -397,6 +402,42 @@ int main() {
397402
;
398403
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
399404
// CHECK-FIXES: {{^ }}if (derived.empty()){{$}}
405+
406+
takesBool(derived.size());
407+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
408+
// CHECK-FIXES: {{^ }}takesBool(!derived.empty());
409+
410+
takesBool(derived.size() == 0);
411+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
412+
// CHECK-FIXES: {{^ }}takesBool(derived.empty());
413+
414+
takesBool(derived.size() != 0);
415+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
416+
// CHECK-FIXES: {{^ }}takesBool(!derived.empty());
417+
418+
bool b1 = derived.size();
419+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
420+
// CHECK-FIXES: {{^ }}bool b1 = !derived.empty();
421+
422+
bool b2(derived.size());
423+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'empty' method should be used
424+
// CHECK-FIXES: {{^ }}bool b2(!derived.empty());
425+
426+
auto b3 = static_cast<bool>(derived.size());
427+
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: the 'empty' method should be used
428+
// CHECK-FIXES: {{^ }}auto b3 = static_cast<bool>(!derived.empty());
429+
430+
auto b4 = (bool)derived.size();
431+
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: the 'empty' method should be used
432+
// CHECK-FIXES: {{^ }}auto b4 = (bool)!derived.empty();
433+
434+
auto b5 = bool(derived.size());
435+
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: the 'empty' method should be used
436+
// CHECK-FIXES: {{^ }}auto b5 = bool(!derived.empty());
437+
438+
return derived.size();
439+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
440+
// CHECK-FIXES: {{^ }}return !derived.empty();
400441
}
401442

402443
#define CHECKSIZE(x) if (x.size()) {}

0 commit comments

Comments
 (0)