aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/test/clang-tidy/checkers/readability
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/checkers/readability')
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h1
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h1
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp23
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp24
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp23
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp10
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp50
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp9
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp24
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp8
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp96
11 files changed, 244 insertions, 25 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h
new file mode 100644
index 0000000..fc9369c
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_begin.h
@@ -0,0 +1 @@
+// Intentionally unguarded begin-pack header used in tests
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h
new file mode 100644
index 0000000..78fd0a9
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/duplicate-include/pack_end.h
@@ -0,0 +1 @@
+// Intentionally unguarded end-pack header used in tests
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
index a8e0eb6..2ed1e93 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -35,6 +35,12 @@ template <typename T>
struct enable_if<true, T> {
typedef T type;
};
+
+template <typename T>
+struct unique_ptr {
+ T &operator*() const;
+ T *operator->() const;
+};
}
template <typename T>
@@ -144,3 +150,20 @@ int *r() {
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
// CHECK-FIXES: return holder.v.data();
}
+
+void s(std::unique_ptr<std::vector<unsigned char>> p) {
+ f(&(*p)[0]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
+ // CHECK-FIXES: f((*p).data());
+}
+
+void t(std::unique_ptr<container_without_data<unsigned char>> p) {
+ // p has no "data" member function, so no warning
+ f(&(*p)[0]);
+}
+
+template <typename T>
+void u(std::unique_ptr<T> p) {
+ // we don't know if 'T' will always have "data" member function, so no warning
+ f(&(*p)[0]);
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp
new file mode 100644
index 0000000..cdc2f44
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/duplicate-include-ignored-files.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-duplicate-include %t -- \
+// RUN: -config="{CheckOptions: {readability-duplicate-include.IgnoredFilesList: 'pack_.*\\.h'}}" \
+// RUN: -header-filter='' -- -I %S/Inputs/duplicate-include
+
+int g;
+#include "duplicate-include.h"
+int h;
+#include "duplicate-include.h"
+int i;
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: duplicate include [readability-duplicate-include]
+// CHECK-FIXES: int g;
+// CHECK-FIXES-NEXT: #include "duplicate-include.h"
+// CHECK-FIXES-NEXT: int h;
+// CHECK-FIXES-NEXT: int i;
+
+#include "pack_begin.h"
+struct A { int x; };
+#include "pack_end.h"
+
+#include "pack_begin.h"
+struct B { int x; };
+#include "pack_end.h"
+
+// No warning here.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
index 9822432..119a3c85 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
@@ -191,3 +191,26 @@ struct S {
void S::f(int y)
{
}
+
+//////////////////////////////////////////////////////
+
+template<typename... Args>
+void variadicFunctionNoWarning(Args... args);
+
+template<>
+void variadicFunctionNoWarning(int a) {}
+
+template<>
+void variadicFunctionNoWarning(int a, int b) {}
+
+template<typename... Args>
+void variadicFunction2WithWarning(int fixed, Args... args);
+
+template<>
+void variadicFunction2WithWarning(int fixed, int a) {}
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'variadicFunction2WithWarning<float>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('wrong'), in primary template declaration: ('fixed')
+void variadicFunction2WithWarning(int wrong, float a) {}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
index fa91995..3e723b8 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
@@ -235,3 +235,13 @@ void testRedundantDependentNTTPCasting() {
// CHECK-MESSAGES: :[[@LINE-4]]:25: note: source type originates from referencing this non-type template parameter
// CHECK-FIXES: T a = V;
}
+
+namespace gh170476 {
+int f(void);
+int g1() {
+ int (*fp)() = (int(*)(void))&f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant explicit casting to the same type 'int (*)()' as the sub-expression, remove this casting [readability-redundant-casting]
+ // CHECK-FIXES: int (*fp)() = (&f);
+ return fp();
+}
+} // namespace gh170476
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp
index 7764490..94e4fc6 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-control-flow.cpp
@@ -7,16 +7,16 @@ void f() {
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement at the end of a function with a void return type [readability-redundant-control-flow]
-// CHECK-FIXES: void f() {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: void f() {
+// CHECK-FIXES-NEXT: }
void g() {
f();
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
-// CHECK-FIXES: f();
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: f();
+// CHECK-FIXES-NEXT: }
void g(int i) {
if (i < 0) {
@@ -40,8 +40,8 @@ void k() {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement at the end of loop statement
-// CHECK-FIXES: for (int i = 0; i < 10; ++i) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (int i = 0; i < 10; ++i) {
+// CHECK-FIXES-NEXT: }
void k2() {
int v[10] = { 0 };
@@ -50,8 +50,8 @@ void k2() {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: for (auto i : v) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (auto i : v) {
+// CHECK-FIXES-NEXT: }
void m() {
int i = 0;
@@ -61,8 +61,8 @@ void m() {
} while (i < 10);
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: {{^ do {$}}
-// CHECK-FIXES-NEXT: ++i;
+// CHECK-FIXES: do {
+// CHECK-FIXES-NEXT: ++i;
// CHECK-FIXES-NEXT: } while (i < 10);
void p() {
@@ -73,9 +73,9 @@ void p() {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: while (i < 10) {
-// CHECK-FIXES-NEXT: ++i;
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: while (i < 10) {
+// CHECK-FIXES-NEXT: ++i;
+// CHECK-FIXES-NEXT: }
void im_not_dead(int i) {
if (i > 0) {
@@ -176,10 +176,10 @@ void template_return(T check) {
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
-// CHECK-FIXES: if (check < T(0)) {
-// CHECK-FIXES-NEXT: {{^ return;$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: if (check < T(0)) {
+// CHECK-FIXES-NEXT: return;
+// CHECK-FIXES-NEXT: }
+// CHECK-FIXES-NEXT: }
template <>
void template_return(int check) {
@@ -189,10 +189,10 @@ void template_return(int check) {
return;
}
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
-// CHECK-FIXES: if (check < 0) {
-// CHECK-FIXES-NEXT: {{^ return;$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: if (check < 0) {
+// CHECK-FIXES-NEXT: return;
+// CHECK-FIXES-NEXT: }
+// CHECK-FIXES-NEXT: }
template <typename T>
void template_loop(T end) {
@@ -201,8 +201,8 @@ void template_loop(T end) {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: for (T i = 0; i < end; ++i) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (T i = 0; i < end; ++i) {
+// CHECK-FIXES-NEXT: }
template <>
void template_loop(int end) {
@@ -211,8 +211,8 @@ void template_loop(int end) {
}
}
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
-// CHECK-FIXES: for (int i = 0; i < end; ++i) {
-// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES: for (int i = 0; i < end; ++i) {
+// CHECK-FIXES-NEXT: }
void call_templates() {
template_return(10);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
index 926cb11..c77608c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
@@ -62,3 +62,12 @@ void exceptions() {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: alignof(3);
}
+
+namespace std {
+ template<class T> T max(T, T);
+ template<class T> T min(T, T);
+} // namespace std
+void ignoreStdMaxMin() {
+ (std::max)(1,2);
+ (std::min)(1,2);
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
index 2efafd1..e8fcd9b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
@@ -267,3 +267,27 @@ WHOLE_TYPE_IN_MACRO Macro2;
#define WHOLE_DECLARATION_IN_MACRO typename NotDependent::R Macro3
WHOLE_DECLARATION_IN_MACRO;
+
+template <typename T> struct Wrapper {};
+template <typename T>
+struct ClassWrapper {
+ using R = T;
+ Wrapper<R> f();
+};
+
+template <typename T>
+Wrapper<typename ClassWrapper<T>::R> ClassWrapper<T>::f() {
+ return {};
+}
+
+template <typename T> struct StructWrapper {};
+template <typename T>
+class ClassWithNestedStruct {
+ struct Nested {};
+ StructWrapper<Nested> f();
+};
+
+template <typename T>
+StructWrapper<typename ClassWithNestedStruct<T>::Nested> ClassWithNestedStruct<T>::f() {
+ return {};
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp
index 53e079b..b8a4953 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/use-concise-preprocessor-directives.cpp
@@ -30,6 +30,14 @@
// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
// CHECK-FIXES: #ifdef FOO
+#if(defined(FOO))
+// CHECK-MESSAGES-23: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
+// CHECK-FIXES-23: #elifdef BAR
+#elif(defined(BAR))
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
+// CHECK-FIXES: #ifdef FOO
#if (defined FOO)
// CHECK-MESSAGES-23: :[[@LINE+2]]:4: warning: preprocessor condition can be written more concisely using '#elifdef' [readability-use-concise-preprocessor-directives]
// CHECK-FIXES-23: # elifdef BAR
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
index 35ade8a..3557018 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
@@ -273,3 +273,99 @@ void useRight() {
}
} // namespace gh121676
+
+void testComments() {
+ int box_depth = 10;
+ int max_depth = 5;
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) // here
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) /* here */
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth)
+ // here
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth)
+ /* here */
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+4]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here
+ // CHECK-FIXES-NEXT: and here
+ // CHECK-FIXES-NEXT: */
+ if (box_depth > max_depth) /* here
+ and here
+ */
+ {
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) { /* here */
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) { // here
+ box_depth = max_depth;
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) {
+ box_depth = max_depth; /* here */
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) {
+ box_depth = max_depth; // here
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); /* here */
+ if (box_depth > max_depth) {
+ box_depth = max_depth;
+ /* here */
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ if (box_depth > max_depth) {
+ box_depth = max_depth;
+ // here
+ }
+
+ // CHECK-MESSAGES: :[[@LINE+5]]:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
+ // CHECK-FIXES: box_depth = std::min(box_depth, max_depth); // here
+ // CHECK-FIXES-NEXT: // and
+ // CHECK-FIXES-NEXT: /* there
+ // CHECK-FIXES-NEXT: again*/
+ if (box_depth > max_depth) {
+ // here
+ box_depth = max_depth; // and
+ /* there
+ again*/
+ }
+}