From 4a2fcce9f0dd67e7ac333ea7c01047bc5c981ae4 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 10 Mar 2026 16:41:17 +0800 Subject: [PATCH] [clang-tidy][NFC] Use universal utility mock in testcases [1/N] (#185431) Follow-up PR of #185210. Only half of the affected test files are converted in this patch. --- .../checkers/Inputs/Headers/utility | 48 +++++++++++++ .../forwarding-reference-overload.cpp | 72 +++++++------------ .../bugprone/move-forwarding-reference.cpp | 14 +--- .../bugprone/unhandled-self-assignment.cpp | 10 +-- .../checkers/bugprone/use-after-move.cpp | 38 +--------- .../missing-std-forward-custom-function.cpp | 16 +---- .../missing-std-forward-cxx23.cpp | 16 +---- .../cppcoreguidelines/missing-std-forward.cpp | 16 +---- ...erence-param-not-moved-custom-function.cpp | 19 +---- .../rvalue-reference-param-not-moved.cpp | 19 +---- .../checkers/performance/for-range-copy.cpp | 16 +---- .../performance/move-const-arg-const-ref.cpp | 34 +-------- .../move-const-arg-trivially-copyable.cpp | 22 +----- .../checkers/performance/move-const-arg.cpp | 32 +-------- .../performance/move-constructor-init.cpp | 11 +-- .../checkers/performance/use-std-move.cpp | 8 +-- 16 files changed, 97 insertions(+), 294 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/utility b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/utility index 30e170b5decc..ab2125e59aba 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/utility +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/utility @@ -2,6 +2,10 @@ #define _UTILITY_ namespace std { + +typedef __SIZE_TYPE__ size_t; +typedef decltype(nullptr) nullptr_t; + template struct remove_reference { typedef T type; }; template @@ -9,10 +13,54 @@ struct remove_reference { typedef T type; }; template struct remove_reference { typedef T type; }; +template +using remove_reference_t = typename remove_reference::type; + template constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { return static_cast::type &&>(__t); } + +template +constexpr T &&forward(remove_reference_t &t) noexcept { + return static_cast(t); +} + +template +constexpr T &&forward(remove_reference_t &&t) noexcept { + return static_cast(t); +} + +template +void swap(T &a, T &b) { + T tmp = move(a); + a = move(b); + b = move(tmp); +} + +template +struct is_same { static constexpr bool value = false; }; +template +struct is_same { static constexpr bool value = true; }; +template +constexpr bool is_same_v = is_same::value; + +template +struct enable_if {}; +template +struct enable_if { typedef T type; }; +template +using enable_if_t = typename enable_if::type; + +template struct remove_cv { using type = T; }; +template struct remove_cv { using type = T; }; +template struct remove_cv { using type = T; }; +template struct remove_cv { using type = T; }; +template using remove_cv_t = typename remove_cv::type; + +template struct remove_cvref { using type = remove_cv_t>; }; +template using remove_cvref_t = typename remove_cvref::type; + } // namespace std #endif // _UTILITY_ diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp index 27315199c7eb..42aaceeb64f6 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp @@ -1,13 +1,8 @@ // RUN: %check_clang_tidy %s bugprone-forwarding-reference-overload %t +#include + namespace std { -template struct enable_if { typedef T type; }; - -template struct enable_if { typedef T type; }; - -template -using enable_if_t = typename enable_if::type; - template struct enable_if_nice { typedef T type; }; } // namespace std @@ -20,30 +15,30 @@ template constexpr bool just_true = true; class Test1 { public: template Test1(T &&n); - // CHECK-NOTES: [[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload] - // CHECK-NOTES: 48:3: note: copy constructor declared here - // CHECK-NOTES: 49:3: note: copy constructor declared here - // CHECK-NOTES: 50:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload] + // CHECK-NOTES: :[[@LINE+24]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+24]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+24]]:3: note: move constructor declared here template Test1(T &&n, int i = 5, ...); // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors - // CHECK-NOTES: 48:3: note: copy constructor declared here - // CHECK-NOTES: 49:3: note: copy constructor declared here - // CHECK-NOTES: 50:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE+18]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+18]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+18]]:3: note: move constructor declared here template ::type> Test1(T &&n); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors - // CHECK-NOTES: 48:3: note: copy constructor declared here - // CHECK-NOTES: 49:3: note: copy constructor declared here - // CHECK-NOTES: 50:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE+11]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+11]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+11]]:3: note: move constructor declared here template Test1(T &&n, typename foo::enable_if::type i = 5, ...); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors - // CHECK-NOTES: 48:3: note: copy constructor declared here - // CHECK-NOTES: 49:3: note: copy constructor declared here - // CHECK-NOTES: 50:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE+4]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+4]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+4]]:3: note: move constructor declared here Test1(const Test1 &other) {} Test1(Test1 &other) {} @@ -58,11 +53,11 @@ public: // Guarded with enable_if. template Test2(T &&n, int i = 5, - std::enable_if_t a = 5, ...); + std::enable_if_t a = 5, ...); // Guarded with enable_if. template ::type &> + sizeof(int) < sizeof(long long), double>::type &> Test2(T &&n); // Guarded with enable_if. @@ -151,23 +146,6 @@ public: // CHECK-NOTES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors }; -namespace std { -template struct is_same { static constexpr bool value = false; }; -template struct is_same { static constexpr bool value = true; }; -template constexpr bool is_same_v = is_same::value; -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; -template using remove_reference_t = typename remove_reference::type; -template struct remove_cv { using type = T; }; -template struct remove_cv { using type = T; }; -template struct remove_cv { using type = T; }; -template struct remove_cv { using type = T; }; -template using remove_cv_t = typename remove_cv::type; -template struct remove_cvref { using type = remove_cv_t>; }; -template using remove_cvref_t = typename remove_cvref::type; -} // namespace std - // Handle enable_if when used as a non-type template parameter. class Test7 { public: @@ -210,32 +188,32 @@ public: std::enable_if_t, bool>, int>> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors - // CHECK-NOTES: 240:3: note: copy constructor declared here - // CHECK-NOTES: 241:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE+27]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+27]]:3: note: move constructor declared here // Requires a default argument (such as a literal, implicit cast expression, etc.) template , long>>*> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors - // CHECK-NOTES: 240:3: note: copy constructor declared here - // CHECK-NOTES: 241:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE+19]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+19]]:3: note: move constructor declared here // Only std::enable_if or std::enable_if_t are supported template ::type* = nullptr> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors - // CHECK-NOTES: 240:3: note: copy constructor declared here - // CHECK-NOTES: 241:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE+11]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+11]]:3: note: move constructor declared here // Only std::enable_if or std::enable_if_t are supported template ::type = 0> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors - // CHECK-NOTES: 240:3: note: copy constructor declared here - // CHECK-NOTES: 241:3: note: move constructor declared here + // CHECK-NOTES: :[[@LINE+3]]:3: note: copy constructor declared here + // CHECK-NOTES: :[[@LINE+3]]:3: note: move constructor declared here Test9(const Test9 &other) = default; Test9(Test9 &&other) = default; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp index 9f453678d1d1..c9f40668f449 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp @@ -1,18 +1,6 @@ // RUN: %check_clang_tidy -std=c++14-or-later %s bugprone-move-forwarding-reference %t -- -- -fno-delayed-template-parsing -namespace std { -template struct remove_reference; - -template struct remove_reference { typedef _Tp type; }; - -template struct remove_reference<_Tp &> { typedef _Tp type; }; - -template struct remove_reference<_Tp &&> { typedef _Tp type; }; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t); - -} // namespace std +#include // Standard case. template void f1(U &&SomeU) { diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp index c2a8ddc08d33..0386c9bfda35 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp @@ -1,15 +1,9 @@ // RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t -- -- -fno-delayed-template-parsing +#include + namespace std { -template -void swap(T &x, T &y) { -} - -template -T &&move(T &x) { -} - template class default_delete {}; template > 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 fd6a3961ba43..983a7ec578c8 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 @@ -11,10 +11,11 @@ // RUN: }}' -- \ // RUN: -fno-delayed-template-parsing +#include + typedef decltype(nullptr) nullptr_t; namespace std { -typedef unsigned size_t; template struct unique_ptr { @@ -112,41 +113,6 @@ DECLARE_STANDARD_CONTAINER(unordered_multimap); typedef basic_string string; -template -struct remove_reference; - -template -struct remove_reference { - typedef _Tp type; -}; - -template -struct remove_reference<_Tp &> { - typedef _Tp type; -}; - -template -struct remove_reference<_Tp &&> { - typedef _Tp type; -}; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept { - return static_cast::type &&>(__t); -} - -template -constexpr _Tp&& -forward(typename std::remove_reference<_Tp>::type& __t) noexcept { - return static_cast<_Tp&&>(__t); -} - -template -constexpr _Tp&& -forward(typename std::remove_reference<_Tp>::type&& __t) noexcept { - return static_cast<_Tp&&>(__t); -} - } // namespace std class A { diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-custom-function.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-custom-function.cpp index deab545eb39a..38f483936221 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-custom-function.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-custom-function.cpp @@ -1,21 +1,7 @@ // RUN: %check_clang_tidy -std=c++14-or-later %s cppcoreguidelines-missing-std-forward %t -- \ // RUN: -config="{CheckOptions: {cppcoreguidelines-missing-std-forward.ForwardFunction: custom_forward}}" -- -fno-delayed-template-parsing -// NOLINTBEGIN -namespace std { - -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; - -template using remove_reference_t = typename remove_reference::type; - -template constexpr T &&forward(remove_reference_t &t) noexcept; -template constexpr T &&forward(remove_reference_t &&t) noexcept; -template constexpr remove_reference_t &&move(T &&x); - -} // namespace std -// NOLINTEND +#include template constexpr decltype(auto) custom_forward(std::remove_reference_t& tmp) noexcept diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-cxx23.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-cxx23.cpp index 723b7893673a..ab39a6dc1ab7 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-cxx23.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-cxx23.cpp @@ -1,26 +1,14 @@ // RUN: %check_clang_tidy -std=c++23-or-later %s cppcoreguidelines-missing-std-forward %t -- -- -fno-delayed-template-parsing -// NOLINTBEGIN +#include +// TODO: move this to namespace std { - -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; - -template using remove_reference_t = typename remove_reference::type; - -template constexpr T &&forward(remove_reference_t &t) noexcept; -template constexpr T &&forward(remove_reference_t &&t) noexcept; -template constexpr remove_reference_t &&move(T &&x); - template concept derived_from = true; template concept integral = true; - } // namespace std -// NOLINTEND // Tests for constrained explicit object parameters (GH#180362). diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp index 98c592db7ce2..d8aa78af43c9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp @@ -1,20 +1,6 @@ // RUN: %check_clang_tidy %s cppcoreguidelines-missing-std-forward %t -- -- -fno-delayed-template-parsing -// NOLINTBEGIN -namespace std { - -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; -template struct remove_reference { using type = T; }; - -template using remove_reference_t = typename remove_reference::type; - -template constexpr T &&forward(remove_reference_t &t) noexcept; -template constexpr T &&forward(remove_reference_t &&t) noexcept; -template constexpr remove_reference_t &&move(T &&x); - -} // namespace std -// NOLINTEND +#include struct S { S(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved-custom-function.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved-custom-function.cpp index db32ff6ef9bf..21766541cfc1 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved-custom-function.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved-custom-function.cpp @@ -1,24 +1,7 @@ // RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \ // RUN: -config="{CheckOptions: {cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true, cppcoreguidelines-rvalue-reference-param-not-moved.MoveFunction: custom_move}}" -- -fno-delayed-template-parsing -// NOLINTBEGIN -namespace std { -template -struct remove_reference; - -template struct remove_reference { typedef _Tp type; }; -template struct remove_reference<_Tp&> { typedef _Tp type; }; -template struct remove_reference<_Tp&&> { typedef _Tp type; }; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept; - -template -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept; - -} -// NOLINTEND +#include struct Obj { diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp index 4e64ea11d3cb..ce8b7e44f8ea 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp @@ -9,24 +9,7 @@ // RUN: %check_clang_tidy -check-suffix=,NONDEDUCED -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \ // RUN: -config="{CheckOptions: {cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: false}}" -- -fno-delayed-template-parsing -// NOLINTBEGIN -namespace std { -template -struct remove_reference; - -template struct remove_reference { typedef _Tp type; }; -template struct remove_reference<_Tp&> { typedef _Tp type; }; -template struct remove_reference<_Tp&&> { typedef _Tp type; }; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept; - -template -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept; - -} -// NOLINTEND +#include struct Obj { Obj(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp index 0b5ef50fdbd7..74bc27ebb206 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp @@ -1,20 +1,6 @@ // RUN: %check_clang_tidy %s performance-for-range-copy %t -- -- -fno-delayed-template-parsing -namespace std { - -template -struct remove_reference { typedef _Tp type; }; -template -struct remove_reference<_Tp&> { typedef _Tp type; }; -template -struct remove_reference<_Tp&&> { typedef _Tp type; }; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast::type &&>(__t); -} - -} // std +#include template struct Iterator { diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-const-ref.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-const-ref.cpp index 95ab6571b9bb..b0678f5d0a5b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-const-ref.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-const-ref.cpp @@ -1,38 +1,8 @@ -// RUN: %check_clang_tidy %s performance-move-const-arg %t \ +// RUN: %check_clang_tidy %s performance-move-const-arg %t -- \ // RUN: -config='{CheckOptions: \ // RUN: {performance-move-const-arg.CheckMoveToConstRef: false}}' -namespace std { -template -struct remove_reference; - -template -struct remove_reference { - typedef _Tp type; -}; - -template -struct remove_reference<_Tp &> { - typedef _Tp type; -}; - -template -struct remove_reference<_Tp &&> { - typedef _Tp type; -}; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast::type &&>(__t); -} - -template -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept { - return static_cast<_Tp &&>(__t); -} - -} // namespace std +#include struct TriviallyCopyable { int i; diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-trivially-copyable.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-trivially-copyable.cpp index 8cc4ecd9e2f0..21d1e6478fb5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-trivially-copyable.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-trivially-copyable.cpp @@ -1,26 +1,8 @@ -// RUN: %check_clang_tidy %s performance-move-const-arg %t \ +// RUN: %check_clang_tidy %s performance-move-const-arg %t -- \ // RUN: -config='{CheckOptions: \ // RUN: {performance-move-const-arg.CheckTriviallyCopyableMove: false}}' -namespace std { - -template struct remove_reference; -template struct remove_reference { typedef _Tp type; }; -template struct remove_reference<_Tp &> { typedef _Tp type; }; -template struct remove_reference<_Tp &&> { typedef _Tp type; }; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast::type &&>(__t); -} - -template -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept { - return static_cast<_Tp &&>(__t); -} - -} // namespace std +#include class NoMoveSemantics { public: diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp index 34d51930ac6c..cbb8c9eabd97 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp @@ -1,36 +1,6 @@ // RUN: %check_clang_tidy %s performance-move-const-arg %t -namespace std { -template -struct remove_reference; - -template -struct remove_reference { - typedef _Tp type; -}; - -template -struct remove_reference<_Tp &> { - typedef _Tp type; -}; - -template -struct remove_reference<_Tp &&> { - typedef _Tp type; -}; - -template -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast::type &&>(__t); -} - -template -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept { - return static_cast<_Tp &&>(__t); -} - -} // namespace std +#include class A { public: diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-constructor-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-constructor-init.cpp index a2d1029d3ebe..4f1f7a0b1eed 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-constructor-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-constructor-init.cpp @@ -1,6 +1,7 @@ // RUN: %check_clang_tidy %s performance-move-constructor-init,modernize-pass-by-value %t -- \ // RUN: -config='{CheckOptions: \ // RUN: {modernize-pass-by-value.ValuesOnly: true}}' + #include // CHECK-FIXES: #include @@ -29,8 +30,8 @@ struct D : B { D() : B() {} D(const D &RHS) : B(RHS) {} // CHECK-NOTES: :[[@LINE+3]]:16: warning: move constructor initializes base class by calling a copy constructor [performance-move-constructor-init] - // CHECK-NOTES: 24:3: note: copy constructor being called - // CHECK-NOTES: 25:3: note: candidate move constructor here + // CHECK-NOTES: :[[@LINE-8]]:3: note: copy constructor being called + // CHECK-NOTES: :[[@LINE-8]]:3: note: candidate move constructor here D(D &&RHS) : B(RHS) {} }; @@ -75,8 +76,8 @@ struct M { B Mem; // CHECK-NOTES: :[[@LINE+1]]:16: warning: move constructor initializes class member by calling a copy constructor [performance-move-constructor-init] M(M &&RHS) : Mem(RHS.Mem) {} - // CHECK-NOTES: 24:3: note: copy constructor being called - // CHECK-NOTES: 25:3: note: candidate move constructor here + // CHECK-NOTES: :[[@LINE-54]]:3: note: copy constructor being called + // CHECK-NOTES: :[[@LINE-54]]:3: note: candidate move constructor here }; struct N { @@ -109,7 +110,7 @@ struct TriviallyCopyable { struct Positive { Positive(Movable M) : M_(M) {} - // CHECK-NOTES: [[@LINE-1]]:12: warning: pass by value and use std::move [modernize-pass-by-value] + // CHECK-NOTES: :[[@LINE-1]]:12: warning: pass by value and use std::move [modernize-pass-by-value] // CHECK-FIXES: Positive(Movable M) : M_(std::move(M)) {} Movable M_; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp index 1b011f2fb4f3..c7014859adf5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp @@ -3,13 +3,7 @@ // Definitions used in the tests // ----------------------------- -namespace std { -template struct remove_reference { typedef T type; }; -template struct remove_reference { typedef T type; }; -template struct remove_reference { typedef T type; }; -template< class T > -constexpr typename remove_reference::type&& move( T&& t ) noexcept; -} +#include struct NonTrivialMoveAssign { NonTrivialMoveAssign() = default;