[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.
This commit is contained in:
mitchell 2026-03-10 16:41:17 +08:00 committed by GitHub
parent c1f3cb73a0
commit 4a2fcce9f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 97 additions and 294 deletions

View File

@ -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_

View File

@ -1,13 +1,8 @@
// RUN: %check_clang_tidy %s bugprone-forwarding-reference-overload %t
#include <utility>
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;
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 @@ public:
// 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 @@ public:
// 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 @@ public:
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;

View File

@ -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) {

View File

@ -1,15 +1,9 @@
// RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t -- -- -fno-delayed-template-parsing
#include <utility>
namespace std {
template <class T>
void swap(T &x, T &y) {
}
template <class T>
T &&move(T &x) {
}
template <typename T> class default_delete {};
template <class T, typename Deleter = std::default_delete<T>>

View File

@ -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 {

View File

@ -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

View File

@ -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).

View File

@ -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();

View File

@ -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 {

View File

@ -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();

View File

@ -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 {

View File

@ -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;

View File

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

View File

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

View File

@ -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_;
};

View File

@ -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;