[llvm-branch-commits] [clang-tools-extra] 53c3acb - [clang-tidy] Add extra tests

Stephen Kelly via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 5 07:48:19 PST 2021


Author: Stephen Kelly
Date: 2021-01-05T15:43:56Z
New Revision: 53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0

URL: https://github.com/llvm/llvm-project/commit/53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0
DIFF: https://github.com/llvm/llvm-project/commit/53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0.diff

LOG: [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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-semicolon-constexpr.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-semicolon-constexpr.cpp
index c18dd7bd1e93..bc82ce1c3ad7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-semicolon-constexpr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-semicolon-constexpr.cpp
@@ -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()
 {

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
index 91ade5242ef1..d637806ba20a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii.cpp
@@ -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>();

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
index 8a69ca42a072..527c79840696 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -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;
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp
index 626dcbd8972b..859d3bf819ff 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp
@@ -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");

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-nodiscard.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-nodiscard.cpp
index 7340713eefa4..12d40bda648a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-nodiscard.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-nodiscard.cpp
@@ -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>

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp
index 6c09fca330b8..64c6ec70ac99 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp
@@ -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"
 

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp
index c2c12a429fb3..f3d27e563193 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp
@@ -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);

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
index 5a7ccae4d52f..1c044e9d25f0 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
@@ -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

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
index ed3d90ca307e..92eca27c53f5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
@@ -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>


        


More information about the llvm-branch-commits mailing list