https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/186652
None >From 2e237aaa803320f62ad6a8b3205ca6dc1c94bdb5 Mon Sep 17 00:00:00 2001 From: Victor Baranov <[email protected]> Date: Sun, 15 Mar 2026 12:14:39 +0300 Subject: [PATCH] [clang-tidy][NFC] Use universal type_traits mock --- .../checkers/Inputs/Headers/std/cstddef | 2 + .../Inputs => Inputs/Headers/std}/type_traits | 26 +++++++++++- .../checkers/Inputs/Headers/std/utility | 42 +------------------ .../checkers/abseil/Inputs/cstddef.h | 10 ----- .../checkers/abseil/Inputs/initializer_list | 11 ----- .../performance/move-constructor-init.cpp | 10 ++--- .../readability/const-return-type.cpp | 9 +--- .../readability/container-data-pointer.cpp | 13 +----- 8 files changed, 36 insertions(+), 87 deletions(-) rename clang-tools-extra/test/clang-tidy/checkers/{abseil/Inputs => Inputs/Headers/std}/type_traits (94%) delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/cstddef.h delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/initializer_list diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/cstddef b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/cstddef index 800285e887cda..c2200b06e6a23 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/cstddef +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/cstddef @@ -14,6 +14,8 @@ namespace std { using ::ptrdiff_t; using ::size_t; + + using nullptr_t = decltype(nullptr); } #endif // _CSTDDEF_ diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/type_traits b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/type_traits similarity index 94% rename from clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/type_traits rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/type_traits index c97ae9c2d14bd..e9b6fa76cb6ff 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/type_traits +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/type_traits @@ -1,4 +1,4 @@ -#include "cstddef.h" +#include "cstddef" namespace std { @@ -94,6 +94,20 @@ struct remove_cv<const volatile T> { template <class T> using remove_cv_t = typename remove_cv<T>::type; +template <class T> +struct remove_const { using type = T; }; +template <class T> +struct remove_const<const T> { using type = T; }; +template <class T> +using remove_const_t = typename remove_const<T>::type; + +template <class T> +struct add_cv { typedef const volatile T type; }; +template <class T> +struct add_const { typedef const T type; }; +template <class T> +struct add_volatile { typedef volatile T type; }; + template <class T> struct decay { private: @@ -123,6 +137,9 @@ struct is_same : false_type {}; template <class T> struct is_same<T, T> : true_type {}; +template <class T, class U> +inline constexpr bool is_same_v = is_same<T, U>::value; + template <class T> struct is_void : is_same<void, typename remove_cv<T>::type> {}; @@ -194,6 +211,13 @@ using is_constructible = is_constructible_<void_t<>, T, Args...>; template <class T, class... Args> inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value; +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; + template <class _Tp> struct __uncvref { typedef typename remove_cv<typename remove_reference<_Tp>::type>::type type; diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/utility b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/utility index e87465118ab2a..deca0c71e2edf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/utility +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/utility @@ -1,20 +1,9 @@ #ifndef _UTILITY_ #define _UTILITY_ -namespace std { - -typedef __SIZE_TYPE__ size_t; -typedef decltype(nullptr) nullptr_t; +#include <type_traits> -template <typename T> -struct remove_reference { typedef T type; }; -template <typename T> -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; +namespace std { template <typename _Tp> constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { @@ -38,33 +27,6 @@ void swap(T &a, T &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_const { using type = T; }; -template <class T> struct remove_const<const T> { using type = T; }; -template <class T> using remove_const_t = typename remove_const<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/abseil/Inputs/cstddef.h b/clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/cstddef.h deleted file mode 100644 index 633260f24f99b..0000000000000 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/cstddef.h +++ /dev/null @@ -1,10 +0,0 @@ -namespace std { - -typedef decltype(sizeof(char)) size_t; - -using nullptr_t = decltype(nullptr); - -} // namespace std - -typedef decltype(sizeof(char)) size_t; -typedef decltype(sizeof(char*)) ptrdiff_t; diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/initializer_list b/clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/initializer_list deleted file mode 100644 index 886a54fe217f4..0000000000000 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/initializer_list +++ /dev/null @@ -1,11 +0,0 @@ - -namespace std { - -template <typename T> -class initializer_list { - public: - const T *a, *b; - initializer_list() noexcept; -}; - -} // namespace std \ No newline at end of file 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 b8395c1eca7e1..ef42e69b37829 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 @@ -2,17 +2,17 @@ // RUN: -config='{CheckOptions: \ // RUN: {modernize-pass-by-value.ValuesOnly: true}}' -- -isystem %S/../Inputs/Headers #include <s.h> +#include <type_traits> // CHECK-FIXES: #include <utility> -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;}; +namespace std { template <typename T> typename remove_reference<T>::type&& move(T&& arg) { return static_cast<typename remove_reference<T>::type&&>(arg); } +} // namespace std struct C { C() = default; @@ -37,7 +37,7 @@ struct D : B { struct E : B { E() : B() {} E(const E &RHS) : B(RHS) {} - E(E &&RHS) : B(move(RHS)) {} // ok + E(E &&RHS) : B(std::move(RHS)) {} // ok }; struct F { @@ -81,7 +81,7 @@ struct M { struct N { B Mem; - N(N &&RHS) : Mem(move(RHS.Mem)) {} + N(N &&RHS) : Mem(std::move(RHS.Mem)) {} }; struct O { diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp index d78ea345b3560..c6e02bd0fe990 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp @@ -3,14 +3,7 @@ // p# = positive test // n# = negative test -namespace std { -template< class T > -struct add_cv { typedef const volatile T type; }; - -template< class T> struct add_const { typedef const T type; }; - -template< class T> struct add_volatile { typedef volatile T type; }; -} +#include <type_traits> const int p1() { // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp index 70ade83eed0f0..80add8191d323 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp @@ -2,21 +2,10 @@ // RUN: %check_clang_tidy -check-suffixes=,WITH-CONFIG %s readability-container-data-pointer %t -- -config="{CheckOptions: {readability-container-data-pointer.IgnoredContainers: '::std::basic_string'}}" -- -fno-delayed-template-parsing #include <string> +#include <type_traits> #include <vector> -#include <utility> - -typedef __SIZE_TYPE__ size_t; namespace std { - -template <typename T> -struct is_integral; - -template <> -struct is_integral<size_t> { - static const bool value = true; -}; - template <typename T> struct unique_ptr { T &operator*() const; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
