From: Stephen Kelly Date: Tue, 29 Dec 2020 23:14:32 +0000 (+0000) Subject: [clang-tidy] Add extra tests X-Git-Tag: llvmorg-13-init~2083 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0;p=platform%2Fupstream%2Fllvm.git [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 --- 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 c18dd7b..bc82ce1 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 91ade52..d637806 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 +void templ() { + T(); +} + +template +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(); + templ(); + Bar(); f(); qux(); 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 8a69ca4..527c798 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 626dcbd..859d3bf 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 7340713..12d40bd 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 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 6c09fca..64c6ec7 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 c2c12a4..f3d27e5 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 f(1); +template +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 f2(1); + +template +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 b(1); +template +struct BatT { + BatT(const T i) {} + + void operator()(const T i) {} +}; +BatT 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 5a7ccae..1c044e9 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 +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 +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 ti2; + ti2.foo(); + TemplPtr 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 ed3d90c..92eca27 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