[clang-tidy] Add extra tests
authorStephen Kelly <steveire@gmail.com>
Tue, 29 Dec 2020 23:14:32 +0000 (23:14 +0000)
committerStephen Kelly <steveire@gmail.com>
Tue, 5 Jan 2021 15:43:56 +0000 (15:43 +0000)
By default, check_clang_tidy runs tests in c++11-or-later mode.

Differential Revision: https://reviews.llvm.org/D94029

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-semicolon-constexpr.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nodiscard.cpp
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp

index c18dd7b..bc82ce1 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-suspicious-semicolon %t -- -- -std=c++17
+// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-suspicious-semicolon %t
 
 void fail()
 {
index 91ade52..d637806 100644 (file)
@@ -36,6 +36,16 @@ struct Ctor {
   }
 };
 
+template <typename T>
+void templ() {
+  T();
+}
+
+template <typename T>
+void neverInstantiated() {
+  T();
+}
+
 void test() {
   Foo(42);
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
@@ -54,6 +64,9 @@ void test() {
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
 // CHECK-FIXES: FooBar give_me_a_name;
 
+  templ<FooBar>();
+  templ<Bar>();
+
   Bar();
   f();
   qux<Foo>();
index 8a69ca4..527c798 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-use-after-move %t -- -- -fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 
index 626dcbd..859d3bf 100644 (file)
@@ -1,5 +1,4 @@
-// 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}]}"
-// FIXME: Fix the checker to work in C++20 mode.
+// RUN: %check_clang_tidy %s modernize-raw-string-literal %t -- -config="{CheckOptions: [{key: modernize-raw-string-literal.ReplaceShorterLiterals, value: 1}]}"
 
 char const *const BackSlash("goink\\frob");
 // 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");
 char const *const TrailingSpace("A line \\with space. \n");
 char const *const TrailingNewLine("A single \\line.\n");
 char const *const AlreadyRaw(R"(foobie\\bletch)");
-char const *const UTF8Literal(u8"foobie\\bletch");
-char const *const UTF8RawLiteral(u8R"(foobie\\bletch)");
+auto const *const UTF8Literal(u8"foobie\\bletch");
+auto const *const UTF8RawLiteral(u8R"(foobie\\bletch)");
 // TODO: enable these tests once all supported compilers
 // support char16_t and char32_t (VS2013 does not)
 // char16_t const *const UTF16Literal(u"foobie\\bletch");
index 7340713..12d40bd 100644 (file)
@@ -1,6 +1,5 @@
-// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
-// RUN:   -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'NO_DISCARD'}]}" \
-// RUN: -- -std=c++17
+// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-nodiscard %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'NO_DISCARD'}]}"
 
 namespace std {
 template <class>
index 6c09fca..64c6ec7 100644 (file)
@@ -1,9 +1,8 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 // RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %t/header.h
-// RUN: %check_clang_tidy -std=c++11 %s performance-unnecessary-value-param %t/temp -- -- -I %t
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t/temp -- -- -I %t
 // RUN: diff %t/header.h %S/Inputs/performance-unnecessary-value-param/header-fixed.h
-// FIXME: Make the test work in all language modes.
 
 #include "header.h"
 
index c2c12a4..f3d27e5 100644 (file)
@@ -81,6 +81,29 @@ struct FooT {
 };
 FooT<int> f(1);
 
+template <class T>
+struct BingT {
+  BingT(const T i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i'
+  // CHECK-FIXES: BingT(T i);
+
+  void operator()(const T i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(T i);
+};
+BingT<int> f2(1);
+
+template <class T>
+struct NeverInstantiatedT {
+  NeverInstantiatedT(const T i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: parameter 'i'
+  // CHECK-FIXES: NeverInstantiatedT(T i);
+
+  void operator()(const T i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(T i);
+};
+
 // Do not match on definitions
 void NF1(const int i) {}
 void NF2(const int *const i) {}
@@ -109,6 +132,13 @@ struct BarT {
   void operator()(const int i) {}
 };
 BarT<int> b(1);
+template <class T>
+struct BatT {
+  BatT(const T i) {}
+
+  void operator()(const T i) {}
+};
+BatT<int> b2(1);
 
 // Do not match on other stuff
 void NF(const alias_type& i);
index 5a7ccae..1c044e9 100644 (file)
@@ -2,6 +2,41 @@
 
 #define NULL 0
 
+template <typename T>
+struct Templ {
+  void foo() {
+    // t1
+    if (mem) // t2
+      delete mem;
+    // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 'if' statement is unnecessary;
+    // CHECK-FIXES: // t1
+    // CHECK-FIXES-NEXT: {{^    }}// t2
+    // CHECK-FIXES-NEXT: delete mem;
+  }
+  T mem;
+};
+
+template <typename T>
+struct TemplPtr {
+  void foo() {
+    // t3
+    if (mem) // t4
+      delete mem;
+    // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 'if' statement is unnecessary;
+    // CHECK-FIXES: // t3
+    // CHECK-FIXES-NEXT: {{^    }}// t4
+    // CHECK-FIXES-NEXT: delete mem;
+  }
+  T *mem;
+};
+
+void instantiate() {
+  Templ<int *> ti2;
+  ti2.foo();
+  TemplPtr<int> ti3;
+  ti3.foo();
+}
+
 void f() {
   int *ps = 0;
   if (ps /**/) // #0
index ed3d90c..92eca27 100644 (file)
@@ -1,9 +1,8 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t \
+// RUN: %check_clang_tidy %s readability-redundant-string-init %t \
 // RUN:   -config="{CheckOptions: \
 // RUN:             [{key: readability-redundant-string-init.StringNames, \
 // RUN:               value: '::std::basic_string;::std::basic_string_view;our::TestString'}] \
 // RUN:             }"
-// FIXME: Fix the checker to work in C++17 mode.
 
 namespace std {
 template <typename T>