Skip to content

Commit 53c3acb

Browse files
committed
[clang-tidy] Add extra tests
By default, check_clang_tidy runs tests in c++11-or-later mode. Differential Revision: https://reviews.llvm.org/D94029
1 parent bf09e25 commit 53c3acb

9 files changed

+87
-13
lines changed

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-semicolon-constexpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s bugprone-suspicious-semicolon %t -- -- -std=c++17
1+
// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-suspicious-semicolon %t
22

33
void fail()
44
{

clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ struct Ctor {
3636
}
3737
};
3838

39+
template <typename T>
40+
void templ() {
41+
T();
42+
}
43+
44+
template <typename T>
45+
void neverInstantiated() {
46+
T();
47+
}
48+
3949
void test() {
4050
Foo(42);
4151
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
@@ -54,6 +64,9 @@ void test() {
5464
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
5565
// CHECK-FIXES: FooBar give_me_a_name;
5666

67+
templ<FooBar>();
68+
templ<Bar>();
69+
5770
Bar();
5871
f();
5972
qux<Foo>();

clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 -fno-delayed-template-parsing
1+
// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-use-after-move %t -- -- -fno-delayed-template-parsing
22

33
typedef decltype(nullptr) nullptr_t;
44

clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s modernize-raw-string-literal %t -- -config="{CheckOptions: [{key: modernize-raw-string-literal.ReplaceShorterLiterals, value: 1}]}"
2-
// FIXME: Fix the checker to work in C++20 mode.
1+
// RUN: %check_clang_tidy %s modernize-raw-string-literal %t -- -config="{CheckOptions: [{key: modernize-raw-string-literal.ReplaceShorterLiterals, value: 1}]}"
32

43
char const *const BackSlash("goink\\frob");
54
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: escaped string literal can be written as a raw string literal [modernize-raw-string-literal]
@@ -47,8 +46,8 @@ char const *const MultibyteSnowman("\xE2\x98\x83");
4746
char const *const TrailingSpace("A line \\with space. \n");
4847
char const *const TrailingNewLine("A single \\line.\n");
4948
char const *const AlreadyRaw(R"(foobie\\bletch)");
50-
char const *const UTF8Literal(u8"foobie\\bletch");
51-
char const *const UTF8RawLiteral(u8R"(foobie\\bletch)");
49+
auto const *const UTF8Literal(u8"foobie\\bletch");
50+
auto const *const UTF8RawLiteral(u8R"(foobie\\bletch)");
5251
// TODO: enable these tests once all supported compilers
5352
// support char16_t and char32_t (VS2013 does not)
5453
// char16_t const *const UTF16Literal(u"foobie\\bletch");

clang-tools-extra/test/clang-tidy/checkers/modernize-use-nodiscard.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
2-
// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'NO_DISCARD'}]}" \
3-
// RUN: -- -std=c++17
1+
// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-nodiscard %t -- \
2+
// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'NO_DISCARD'}]}"
43

54
namespace std {
65
template <class>

clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// RUN: rm -rf %t
22
// RUN: mkdir %t
33
// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %t/header.h
4-
// RUN: %check_clang_tidy -std=c++11 %s performance-unnecessary-value-param %t/temp -- -- -I %t
4+
// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t/temp -- -- -I %t
55
// RUN: diff %t/header.h %S/Inputs/performance-unnecessary-value-param/header-fixed.h
6-
// FIXME: Make the test work in all language modes.
76

87
#include "header.h"
98

clang-tools-extra/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ struct FooT {
8181
};
8282
FooT<int> f(1);
8383

84+
template <class T>
85+
struct BingT {
86+
BingT(const T i);
87+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i'
88+
// CHECK-FIXES: BingT(T i);
89+
90+
void operator()(const T i);
91+
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
92+
// CHECK-FIXES: void operator()(T i);
93+
};
94+
BingT<int> f2(1);
95+
96+
template <class T>
97+
struct NeverInstantiatedT {
98+
NeverInstantiatedT(const T i);
99+
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: parameter 'i'
100+
// CHECK-FIXES: NeverInstantiatedT(T i);
101+
102+
void operator()(const T i);
103+
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
104+
// CHECK-FIXES: void operator()(T i);
105+
};
106+
84107
// Do not match on definitions
85108
void NF1(const int i) {}
86109
void NF2(const int *const i) {}
@@ -109,6 +132,13 @@ struct BarT {
109132
void operator()(const int i) {}
110133
};
111134
BarT<int> b(1);
135+
template <class T>
136+
struct BatT {
137+
BatT(const T i) {}
138+
139+
void operator()(const T i) {}
140+
};
141+
BatT<int> b2(1);
112142

113143
// Do not match on other stuff
114144
void NF(const alias_type& i);

clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22

33
#define NULL 0
44

5+
template <typename T>
6+
struct Templ {
7+
void foo() {
8+
// t1
9+
if (mem) // t2
10+
delete mem;
11+
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 'if' statement is unnecessary;
12+
// CHECK-FIXES: // t1
13+
// CHECK-FIXES-NEXT: {{^ }}// t2
14+
// CHECK-FIXES-NEXT: delete mem;
15+
}
16+
T mem;
17+
};
18+
19+
template <typename T>
20+
struct TemplPtr {
21+
void foo() {
22+
// t3
23+
if (mem) // t4
24+
delete mem;
25+
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 'if' statement is unnecessary;
26+
// CHECK-FIXES: // t3
27+
// CHECK-FIXES-NEXT: {{^ }}// t4
28+
// CHECK-FIXES-NEXT: delete mem;
29+
}
30+
T *mem;
31+
};
32+
33+
void instantiate() {
34+
Templ<int *> ti2;
35+
ti2.foo();
36+
TemplPtr<int> ti3;
37+
ti3.foo();
38+
}
39+
540
void f() {
641
int *ps = 0;
742
if (ps /**/) // #0

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t \
1+
// RUN: %check_clang_tidy %s readability-redundant-string-init %t \
22
// RUN: -config="{CheckOptions: \
33
// RUN: [{key: readability-redundant-string-init.StringNames, \
44
// RUN: value: '::std::basic_string;::std::basic_string_view;our::TestString'}] \
55
// RUN: }"
6-
// FIXME: Fix the checker to work in C++17 mode.
76

87
namespace std {
98
template <typename T>

0 commit comments

Comments
 (0)