Author: mitchell Date: 2026-03-10T16:41:17+08:00 New Revision: 4a2fcce9f0dd67e7ac333ea7c01047bc5c981ae4
URL: https://github.com/llvm/llvm-project/commit/4a2fcce9f0dd67e7ac333ea7c01047bc5c981ae4 DIFF: https://github.com/llvm/llvm-project/commit/4a2fcce9f0dd67e7ac333ea7c01047bc5c981ae4.diff LOG: [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. Added: Modified: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/utility clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-custom-function.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward-cxx23.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved-custom-function.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-const-ref.cpp clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg-trivially-copyable.cpp clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp clang-tools-extra/test/clang-tidy/checkers/performance/move-constructor-init.cpp clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp Removed: ################################################################################ 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 30e170b5decc1..ab2125e59abae 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 <typename T> struct remove_reference { typedef T type; }; template <typename T> @@ -9,10 +13,54 @@ struct remove_reference<T &> { typedef T type; }; template <typename T> struct remove_reference<T &&> { typedef T type; }; +template <typename T> +using remove_reference_t = typename remove_reference<T>::type; + template <typename _Tp> constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { return static_cast<typename std::remove_reference<_Tp>::type &&>(__t); } + +template <typename T> +constexpr T &&forward(remove_reference_t<T> &t) noexcept { + return static_cast<T &&>(t); +} + +template <typename T> +constexpr T &&forward(remove_reference_t<T> &&t) noexcept { + return static_cast<T &&>(t); +} + +template <typename T> +void swap(T &a, T &b) { + T tmp = move(a); + a = move(b); + b = move(tmp); +} + +template <class T, class U> +struct is_same { static constexpr bool value = false; }; +template <class T> +struct is_same<T, T> { static constexpr bool value = true; }; +template <class T, class U> +constexpr bool is_same_v = is_same<T, U>::value; + +template <bool B, class T = void> +struct enable_if {}; +template <class T> +struct enable_if<true, T> { typedef T type; }; +template <bool B, class T = void> +using enable_if_t = typename enable_if<B, T>::type; + +template <class T> struct remove_cv { using type = T; }; +template <class T> struct remove_cv<const T> { using type = T; }; +template <class T> struct remove_cv<volatile T> { using type = T; }; +template <class T> struct remove_cv<const volatile T> { using type = T; }; +template <class T> using remove_cv_t = typename remove_cv<T>::type; + +template <class T> struct remove_cvref { using type = remove_cv_t<remove_reference_t<T>>; }; +template <class T> using remove_cvref_t = typename remove_cvref<T>::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 27315199c7eba..42aaceeb64f64 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 -namespace std { -template <bool B, class T = void> struct enable_if { typedef T type; }; - -template <class T> struct enable_if<true, T> { typedef T type; }; - -template <bool B, class T = void> -using enable_if_t = typename enable_if<B, T>::type; +#include <utility> +namespace std { template <class T> struct enable_if_nice { typedef T type; }; } // namespace std @@ -20,30 +15,30 @@ template <typename T> constexpr bool just_true = true; class Test1 { public: template <typename T> 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 <typename T> 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 <typename T, typename U = typename std::enable_if_nice<T>::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 <typename T> Test1(T &&n, typename foo::enable_if<long>::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 @@ template <typename U> class Test2 { // Guarded with enable_if. template <typename T> Test2(T &&n, int i = 5, - std::enable_if_t<sizeof(int) < sizeof(long), int> a = 5, ...); + std::enable_if_t<sizeof(int) < sizeof(long long), int> a = 5, ...); // Guarded with enable_if. template <typename T, typename X = typename std::enable_if< - sizeof(int) < sizeof(long), double>::type &> + sizeof(int) < sizeof(long long), double>::type &> Test2(T &&n); // Guarded with enable_if. @@ -151,23 +146,6 @@ class variant { // CHECK-NOTES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors }; -namespace std { -template <class T, class U> struct is_same { static constexpr bool value = false; }; -template <class T> struct is_same<T, T> { static constexpr bool value = true; }; -template <class T, class U> constexpr bool is_same_v = is_same<T, U>::value; -template <class T> struct remove_reference { using type = T; }; -template <class T> struct remove_reference<T&> { using type = T; }; -template <class T> struct remove_reference<T&&> { using type = T; }; -template <class T> using remove_reference_t = typename remove_reference<T>::type; -template <class T> struct remove_cv { using type = T; }; -template <class T> struct remove_cv<const T> { using type = T; }; -template <class T> struct remove_cv<volatile T> { using type = T; }; -template <class T> struct remove_cv<const volatile T> { using type = T; }; -template <class T> using remove_cv_t = typename remove_cv<T>::type; -template <class T> struct remove_cvref { using type = remove_cv_t<remove_reference_t<T>>; }; -template <class T> using remove_cvref_t = typename remove_cvref<T>::type; -} // namespace std - // Handle enable_if when used as a non-type template parameter. class Test7 { public: @@ -210,32 +188,32 @@ class Test9 { std::enable_if_t<std::is_same_v<std::remove_cvref_t<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 <class T, std::enable_if_t<std::is_same_v<std::remove_cvref_t<T>, 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 <class T, typename std::enable_if_nice<T>::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 <class T, typename foo::enable_if<T>::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 9f453678d1d19..c9f40668f449a 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 <typename> struct remove_reference; - -template <typename _Tp> struct remove_reference { typedef _Tp type; }; - -template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; }; - -template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; }; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t); - -} // namespace std +#include <utility> // Standard case. template <typename T, typename U> 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 c2a8ddc08d330..0386c9bfda359 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,14 +1,8 @@ // RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t -- -- -fno-delayed-template-parsing -namespace std { - -template <class T> -void swap(T &x, T &y) { -} +#include <utility> -template <class T> -T &&move(T &x) { -} +namespace std { template <typename T> class default_delete {}; 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 fd6a3961ba43b..983a7ec578c8d 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 <utility> + typedef decltype(nullptr) nullptr_t; namespace std { -typedef unsigned size_t; template <typename T> struct unique_ptr { @@ -112,41 +113,6 @@ DECLARE_STANDARD_CONTAINER(unordered_multimap); typedef basic_string<char> string; -template <typename> -struct remove_reference; - -template <typename _Tp> -struct remove_reference { - typedef _Tp type; -}; - -template <typename _Tp> -struct remove_reference<_Tp &> { - typedef _Tp type; -}; - -template <typename _Tp> -struct remove_reference<_Tp &&> { - typedef _Tp type; -}; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept { - return static_cast<typename remove_reference<_Tp>::type &&>(__t); -} - -template <class _Tp> -constexpr _Tp&& -forward(typename std::remove_reference<_Tp>::type& __t) noexcept { - return static_cast<_Tp&&>(__t); -} - -template <class _Tp> -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 deab545eb39a3..38f483936221b 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 <typename T> struct remove_reference { using type = T; }; -template <typename T> struct remove_reference<T&> { using type = T; }; -template <typename T> struct remove_reference<T&&> { using type = T; }; - -template <typename T> using remove_reference_t = typename remove_reference<T>::type; - -template <typename T> constexpr T &&forward(remove_reference_t<T> &t) noexcept; -template <typename T> constexpr T &&forward(remove_reference_t<T> &&t) noexcept; -template <typename T> constexpr remove_reference_t<T> &&move(T &&x); - -} // namespace std -// NOLINTEND +#include <utility> template<class T> constexpr decltype(auto) custom_forward(std::remove_reference_t<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 723b7893673a1..ab39a6dc1ab74 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 <utility> +// TODO: move this to <concept> namespace std { - -template <typename T> struct remove_reference { using type = T; }; -template <typename T> struct remove_reference<T&> { using type = T; }; -template <typename T> struct remove_reference<T&&> { using type = T; }; - -template <typename T> using remove_reference_t = typename remove_reference<T>::type; - -template <typename T> constexpr T &&forward(remove_reference_t<T> &t) noexcept; -template <typename T> constexpr T &&forward(remove_reference_t<T> &&t) noexcept; -template <typename T> constexpr remove_reference_t<T> &&move(T &&x); - template <class T, class U> concept derived_from = true; template <class T> 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 98c592db7ce22..d8aa78af43c9f 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 <typename T> struct remove_reference { using type = T; }; -template <typename T> struct remove_reference<T&> { using type = T; }; -template <typename T> struct remove_reference<T&&> { using type = T; }; - -template <typename T> using remove_reference_t = typename remove_reference<T>::type; - -template <typename T> constexpr T &&forward(remove_reference_t<T> &t) noexcept; -template <typename T> constexpr T &&forward(remove_reference_t<T> &&t) noexcept; -template <typename T> constexpr remove_reference_t<T> &&move(T &&x); - -} // namespace std -// NOLINTEND +#include <utility> 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 db32ff6ef9bf3..21766541cfc1c 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 <typename> -struct remove_reference; - -template <typename _Tp> struct remove_reference { typedef _Tp type; }; -template <typename _Tp> struct remove_reference<_Tp&> { typedef _Tp type; }; -template <typename _Tp> struct remove_reference<_Tp&&> { typedef _Tp type; }; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept; - -template <typename _Tp> -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept; - -} -// NOLINTEND +#include <utility> 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 4e64ea11d3cb4..ce8b7e44f8ea0 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 <typename> -struct remove_reference; - -template <typename _Tp> struct remove_reference { typedef _Tp type; }; -template <typename _Tp> struct remove_reference<_Tp&> { typedef _Tp type; }; -template <typename _Tp> struct remove_reference<_Tp&&> { typedef _Tp type; }; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept; - -template <typename _Tp> -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept; - -} -// NOLINTEND +#include <utility> 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 0b5ef50fdbd7f..74bc27ebb2066 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 <typename _Tp> -struct remove_reference { typedef _Tp type; }; -template <typename _Tp> -struct remove_reference<_Tp&> { typedef _Tp type; }; -template <typename _Tp> -struct remove_reference<_Tp&&> { typedef _Tp type; }; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast<typename std::remove_reference<_Tp>::type &&>(__t); -} - -} // std +#include <utility> template <typename T> 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 95ab6571b9bb9..b0678f5d0a5b7 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 <typename> -struct remove_reference; - -template <typename _Tp> -struct remove_reference { - typedef _Tp type; -}; - -template <typename _Tp> -struct remove_reference<_Tp &> { - typedef _Tp type; -}; - -template <typename _Tp> -struct remove_reference<_Tp &&> { - typedef _Tp type; -}; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast<typename std::remove_reference<_Tp>::type &&>(__t); -} - -template <typename _Tp> -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept { - return static_cast<_Tp &&>(__t); -} - -} // namespace std +#include <utility> 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 8cc4ecd9e2f0a..21d1e6478fb55 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 <typename> struct remove_reference; -template <typename _Tp> struct remove_reference { typedef _Tp type; }; -template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; }; -template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; }; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast<typename std::remove_reference<_Tp>::type &&>(__t); -} - -template <typename _Tp> -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept { - return static_cast<_Tp &&>(__t); -} - -} // namespace std +#include <utility> 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 34d51930ac6c8..cbb8c9eabd974 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 <typename> -struct remove_reference; - -template <typename _Tp> -struct remove_reference { - typedef _Tp type; -}; - -template <typename _Tp> -struct remove_reference<_Tp &> { - typedef _Tp type; -}; - -template <typename _Tp> -struct remove_reference<_Tp &&> { - typedef _Tp type; -}; - -template <typename _Tp> -constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { - return static_cast<typename std::remove_reference<_Tp>::type &&>(__t); -} - -template <typename _Tp> -constexpr _Tp && -forward(typename remove_reference<_Tp>::type &__t) noexcept { - return static_cast<_Tp &&>(__t); -} - -} // namespace std +#include <utility> 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 a2d1029d3ebe9..4f1f7a0b1eed8 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 <s.h> // CHECK-FIXES: #include <utility> @@ -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 1b011f2fb4f3c..c7014859adf50 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<class T> struct remove_reference { typedef T type; }; -template<class T> struct remove_reference<T&> { typedef T type; }; -template<class T> struct remove_reference<T&&> { typedef T type; }; -template< class T > -constexpr typename remove_reference<T>::type&& move( T&& t ) noexcept; -} +#include <utility> struct NonTrivialMoveAssign { NonTrivialMoveAssign() = default; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
