[clang-tools-extra] [clang-tidy][NFC] Use universal memory mock for smart ptrs (PR #186649)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 15 15:44:55 PDT 2026
https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/186649
>From d6c5766f82977f060d72e0d0eb6d85c60bb0090e Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Mon, 16 Mar 2026 01:44:44 +0300
Subject: [PATCH] [clang-tidy][NFC] Use universal memory mock for smart ptrs
---
.../checkers/Inputs/Headers/std/memory | 170 ++++++++++++++++++
.../bugprone/shared-ptr-array-mismatch.cpp | 12 +-
.../bugprone/unhandled-self-assignment.cpp | 19 +-
.../bugprone/unique-ptr-array-mismatch.cpp | 23 +--
.../checkers/bugprone/unused-return-value.cpp | 14 +-
.../checkers/bugprone/use-after-move.cpp | 30 +---
.../avoid-const-or-ref-data-members.cpp | 7 +-
.../checkers/misc/uniqueptr-reset-release.cpp | 16 +-
.../Inputs/replace-auto-ptr/memory.h | 45 -----
.../modernize/Inputs/smart-ptr/shared_ptr.h | 34 +---
.../modernize/Inputs/smart-ptr/unique_ptr.h | 29 +--
.../checkers/modernize/make-shared-header.cpp | 5 +-
.../checkers/modernize/make-unique-cxx11.cpp | 6 +-
.../modernize/make-unique-default-init.cpp | 6 +-
.../checkers/modernize/make-unique-header.cpp | 5 +-
.../checkers/modernize/make-unique-macros.cpp | 2 +-
.../checkers/modernize/replace-auto-ptr.cpp | 4 +-
.../checkers/modernize/use-emplace.cpp | 7 +-
.../checkers/modernize/use-ranges.cpp | 2 +-
...us-smartptr-reset-call-custom-pointers.cpp | 5 +-
.../ambiguous-smartptr-reset-call.cpp | 5 +-
.../readability/container-data-pointer.cpp | 9 +-
.../readability/container-size-empty.cpp | 9 +-
.../redundant-smartptr-get-macros.cpp | 12 +-
.../readability/redundant-smartptr-get.cpp | 35 +---
.../readability/uniqueptr-delete-release.cpp | 22 +--
26 files changed, 205 insertions(+), 328 deletions(-)
delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/replace-auto-ptr/memory.h
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/memory b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/memory
index 2ec18dbec18f4..201ebd59555f3 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/memory
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/memory
@@ -1,8 +1,178 @@
#ifndef _MEMORY_
#define _MEMORY_
+#include "stddef.h"
+
namespace std {
+template <typename T>
+struct default_delete {};
+
+template <typename T>
+struct default_delete<T[]> {};
+
+template <typename T, typename Deleter = default_delete<T>>
+class unique_ptr {
+public:
+ unique_ptr() noexcept {}
+ explicit unique_ptr(T *p) noexcept {}
+ unique_ptr(T *p, Deleter d) noexcept {}
+ unique_ptr(const unique_ptr &) = delete;
+ unique_ptr(unique_ptr &&t) noexcept {}
+ template <typename U, typename E>
+ unique_ptr(unique_ptr<U, E> &&t) noexcept {}
+ ~unique_ptr() {}
+
+ T &operator*() const { return *ptr; }
+ T *operator->() const { return ptr; }
+ explicit operator bool() const noexcept { return ptr != nullptr; }
+
+ T *get() const { return ptr; }
+ T *release() { return ptr; }
+ void reset() {}
+ void reset(T *p) {}
+
+ unique_ptr &operator=(unique_ptr &) = delete;
+ template <typename U, typename E>
+ unique_ptr &operator=(unique_ptr<U, E> &) = delete;
+ unique_ptr &operator=(unique_ptr &&) noexcept { return *this; }
+ template <typename U, typename E>
+ unique_ptr &operator=(unique_ptr<U, E> &&) noexcept { return *this; }
+
+ bool operator==(const unique_ptr &) const noexcept { return false; }
+ bool operator!=(const unique_ptr &) const noexcept { return true; }
+
+private:
+ T *ptr = nullptr;
+};
+
+template <typename T, typename Deleter>
+class unique_ptr<T[], Deleter> {
+public:
+ unique_ptr() noexcept {}
+ template <typename U>
+ explicit unique_ptr(U p) noexcept {}
+ template <typename U>
+ unique_ptr(U p, Deleter d) noexcept {}
+ ~unique_ptr() {}
+
+ T &operator[](size_t i) const { return ptr[i]; }
+ T *get() const { return ptr; }
+ explicit operator bool() const noexcept { return ptr != nullptr; }
+
+ void reset() {}
+ void reset(T *p) {}
+
+private:
+ T *ptr = nullptr;
+};
+
+template <typename T, typename... Args>
+unique_ptr<T> make_unique(Args &&...args) {
+ return unique_ptr<T>(new T(static_cast<Args &&>(args)...));
+}
+
+template <typename T>
+class shared_ptr {
+public:
+ shared_ptr() {}
+ explicit shared_ptr(T *p) {}
+ template <typename Y>
+ explicit shared_ptr(Y *p) {}
+ template <typename Y, typename D>
+ shared_ptr(Y *p, D d) {}
+ shared_ptr(const shared_ptr &) {}
+ shared_ptr(shared_ptr &&) {}
+ ~shared_ptr() {}
+
+ T &operator*() const { return *this->get(); }
+ T *operator->() const { return this->get(); }
+ T *get() const { return ptr; }
+ void reset() {}
+ void reset(T *p) {}
+ explicit operator bool() const noexcept { return this->get() != nullptr; }
+
+ shared_ptr &operator=(shared_ptr &&) { return *this; }
+ template <typename U>
+ shared_ptr &operator=(shared_ptr<U> &&) { return *this; }
+
+private:
+ T *ptr = nullptr;
+};
+
+template <typename T>
+class shared_ptr<T[]> {
+public:
+ shared_ptr() {}
+ explicit shared_ptr(T *p) {}
+ template <typename Y>
+ explicit shared_ptr(Y *p) {}
+ template <typename Y, typename D>
+ shared_ptr(Y *p, D d) {}
+ shared_ptr(const shared_ptr &) {}
+ shared_ptr(shared_ptr &&) {}
+ ~shared_ptr() {}
+
+ T &operator[](size_t i) const { return ptr[i]; }
+ T *get() const { return ptr; }
+ void reset() {}
+ void reset(T *p) {}
+ explicit operator bool() const noexcept { return ptr != nullptr; }
+
+private:
+ T *ptr = nullptr;
+};
+
+template <typename T, typename... Args>
+shared_ptr<T> make_shared(Args &&...args) {
+ return shared_ptr<T>(new T(static_cast<Args &&>(args)...));
+}
+
+template <typename T>
+class weak_ptr {
+public:
+ weak_ptr() {}
+ bool expired() const { return true; }
+};
+
+template <typename Y>
+struct auto_ptr_ref {
+ Y *ptr;
+};
+
+template <typename X>
+class auto_ptr {
+public:
+ typedef X element_type;
+ explicit auto_ptr(X *p = 0) throw() {}
+ auto_ptr(auto_ptr &a) throw() {}
+ template <typename Y>
+ auto_ptr(auto_ptr<Y> &a) throw() {}
+ auto_ptr &operator=(auto_ptr &a) throw() { return *this; }
+ template <typename Y>
+ auto_ptr &operator=(auto_ptr<Y> &a) throw() { return *this; }
+ auto_ptr &operator=(auto_ptr_ref<X> r) throw() { return *this; }
+ ~auto_ptr() throw() {}
+ auto_ptr(auto_ptr_ref<X> r) throw() {}
+ template <typename Y>
+ operator auto_ptr_ref<Y>() throw() {
+ auto_ptr_ref<Y> r;
+ r.ptr = ptr;
+ return r;
+ }
+ template <typename Y>
+ operator auto_ptr<Y>() throw() { return auto_ptr<Y>(ptr); }
+
+private:
+ X *ptr = nullptr;
+};
+
+template <>
+class auto_ptr<void> {
+public:
+ typedef void element_type;
+};
+
template <typename T>
class allocator {};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
index 70449e6bfc24c..dab7ef0d071f5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
@@ -1,16 +1,6 @@
// RUN: %check_clang_tidy %s bugprone-shared-ptr-array-mismatch %t
-namespace std {
-
-template <typename T>
-struct shared_ptr {
- template <class Y>
- explicit shared_ptr(Y *) {}
- template <class Y, class Deleter>
- shared_ptr(Y *, Deleter) {}
-};
-
-} // namespace std
+#include <memory>
struct A {};
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 0386c9bfda359..c0a65f3cb9bef 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,27 +1,10 @@
// RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t -- -- -fno-delayed-template-parsing
#include <utility>
+#include <memory>
namespace std {
-template <typename T> class default_delete {};
-
-template <class T, typename Deleter = std::default_delete<T>>
-class unique_ptr {
-};
-
-template <class T>
-class shared_ptr {
-};
-
-template <class T>
-class weak_ptr {
-};
-
-template <class T>
-class auto_ptr {
-};
-
namespace pmr {
template <typename TYPE = void>
class allocator {};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unique-ptr-array-mismatch.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unique-ptr-array-mismatch.cpp
index 494e83dce3720..7076461497fc3 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unique-ptr-array-mismatch.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unique-ptr-array-mismatch.cpp
@@ -1,27 +1,6 @@
// RUN: %check_clang_tidy %s bugprone-unique-ptr-array-mismatch %t
-namespace std {
-
-template<class T> struct default_delete {};
-template<class T> struct default_delete<T[]> {};
-
-template<class T, class Deleter = std::default_delete<T>>
-class unique_ptr {
-public:
- explicit unique_ptr(T* p) noexcept;
- unique_ptr(T* p, Deleter d1 ) noexcept;
-};
-
-template <class T, class Deleter>
-class unique_ptr<T[], Deleter> {
-public:
- template<class U>
- explicit unique_ptr(U p) noexcept;
- template<class U>
- unique_ptr(U p, Deleter d1) noexcept;
-};
-
-} // namespace std
+#include <memory>
struct A {};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
index 7ecacabef1a0b..3fa87b94dc6b4 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp
@@ -1,6 +1,7 @@
// RUN: %check_clang_tidy %s bugprone-unused-return-value %t -- \
// RUN: --config="{CheckOptions: {bugprone-unused-return-value.AllowCastToVoid: true}}" -- -fexceptions
#include <vector>
+#include <memory>
namespace std {
@@ -26,19 +27,6 @@ ForwardIt remove_if(ForwardIt, ForwardIt, UnaryPredicate);
template <typename ForwardIt>
ForwardIt unique(ForwardIt, ForwardIt);
-template <typename T>
-struct default_delete;
-
-template <typename T, typename Deleter = std::default_delete<T>>
-struct unique_ptr {
- unique_ptr();
- unique_ptr(unique_ptr const&);
- unique_ptr(unique_ptr &&);
- unique_ptr& operator=(unique_ptr const&);
- unique_ptr& operator=(unique_ptr &&);
- T *release() noexcept;
-};
-
template <typename T>
struct char_traits;
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 983a7ec578c8d..5d95c44fc318f 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
@@ -12,38 +12,12 @@
// RUN: -fno-delayed-template-parsing
#include <utility>
+#include <memory>
typedef decltype(nullptr) nullptr_t;
namespace std {
-template <typename T>
-struct unique_ptr {
- unique_ptr();
- T *get() const;
- explicit operator bool() const;
- void reset(T *ptr);
- T &operator*() const;
- T *operator->() const;
- T& operator[](size_t i) const;
-};
-
-template <typename T>
-struct shared_ptr {
- shared_ptr();
- T *get() const;
- explicit operator bool() const;
- void reset(T *ptr);
- T &operator*() const;
- T *operator->() const;
-};
-
-template <typename T>
-struct weak_ptr {
- weak_ptr();
- bool expired() const;
-};
-
template <typename T>
struct optional {
optional();
@@ -224,7 +198,7 @@ void standardSmartPtr() {
// CHECK-NOTES: [[@LINE-3]]:5: note: move occurred here
}
{
- std::unique_ptr<A> ptr;
+ std::unique_ptr<A[]> ptr;
std::move(ptr);
ptr[0];
// CHECK-NOTES: [[@LINE-1]]:5: warning: 'ptr' used after it was moved
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
index 19da88300aec4..bd6e1ce301fd5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp
@@ -1,11 +1,6 @@
// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
-namespace std {
-template <typename T>
-struct unique_ptr {};
-template <typename T>
-struct shared_ptr {};
-} // namespace std
+#include <memory>
namespace gsl {
template <typename T>
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/uniqueptr-reset-release.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/uniqueptr-reset-release.cpp
index 629f55a96f3b8..f14598d2eb4b9 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/uniqueptr-reset-release.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/uniqueptr-reset-release.cpp
@@ -2,21 +2,7 @@
// CHECK-FIXES: #include <utility>
-namespace std {
-
-template <typename T>
-struct default_delete {};
-
-template <typename T, class Deleter = std::default_delete<T>>
-struct unique_ptr {
- unique_ptr();
- explicit unique_ptr(T *);
- template <typename U, typename E>
- unique_ptr(unique_ptr<U, E> &&);
- void reset(T *);
- T *release();
-};
-} // namespace std
+#include <memory>
struct Foo {};
struct Bar : Foo {};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/replace-auto-ptr/memory.h b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/replace-auto-ptr/memory.h
deleted file mode 100644
index bc476ced927a5..0000000000000
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/replace-auto-ptr/memory.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef INPUTS_MEMORY_H
-#define INPUTS_MEMORY_H
-
-namespace std {
-
-inline namespace _1 {
-
-template <class Y> struct auto_ptr_ref {
- Y *y_;
-};
-
-template <class X> class auto_ptr {
-public:
- typedef X element_type;
- explicit auto_ptr(X *p = 0) throw() {}
- auto_ptr(auto_ptr &) throw() {}
- template <class Y> auto_ptr(auto_ptr<Y> &) throw() {}
- auto_ptr &operator=(auto_ptr &) throw() { return *this; }
- template <class Y> auto_ptr &operator=(auto_ptr<Y> &) throw() {
- return *this;
- }
- auto_ptr &operator=(auto_ptr_ref<X> r) throw() { return *this; }
- ~auto_ptr() throw() {}
- auto_ptr(auto_ptr_ref<X> r) throw() : x_(r.y_) {}
- template <class Y> operator auto_ptr_ref<Y>() throw() {
- auto_ptr_ref<Y> r;
- r.y_ = x_;
- return r;
- }
- template <class Y> operator auto_ptr<Y>() throw() { return auto_ptr<Y>(x_); }
-
-private:
- X *x_;
-};
-
-template <> class auto_ptr<void> {
-public:
- typedef void element_type;
-};
-
-} // namespace _1
-
-} // end namespace std
-
-#endif // INPUTS_MEMORY_H
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
index 337cb28228b09..ef00360c87d72 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
@@ -1,33 +1 @@
-namespace std {
-
-template <typename type>
-class __shared_ptr {
-protected:
- __shared_ptr();
- __shared_ptr(type *ptr);
- ~__shared_ptr();
-public:
- type &operator*() { return *ptr; }
- type *operator->() { return ptr; }
- type *release();
- void reset();
- void reset(type *pt);
-
-private:
- type *ptr;
-};
-
-template <typename type>
-class shared_ptr : public __shared_ptr<type> {
-public:
- shared_ptr();
- shared_ptr(type *ptr);
- shared_ptr(const shared_ptr<type> &t);
- shared_ptr(shared_ptr<type> &&t);
- ~shared_ptr();
- shared_ptr &operator=(shared_ptr &&);
- template <typename T>
- shared_ptr &operator=(shared_ptr<T> &&);
-};
-
-} // namespace std
+#include <memory>
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/unique_ptr.h b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/unique_ptr.h
index 5dc9e02b637a2..ef00360c87d72 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/unique_ptr.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/unique_ptr.h
@@ -1,28 +1 @@
-namespace std {
-
-template <typename T>
-class default_delete {};
-
-template <typename type, typename Deleter = std::default_delete<type>>
-class unique_ptr {
-public:
- unique_ptr() {}
- unique_ptr(type *ptr) {}
- unique_ptr(const unique_ptr<type> &t) = delete;
- unique_ptr(unique_ptr<type> &&t) {}
- ~unique_ptr() {}
- type &operator*() { return *ptr; }
- type *operator->() { return ptr; }
- type *release() { return ptr; }
- void reset() {}
- void reset(type *pt) {}
- void reset(type pt) {}
- unique_ptr &operator=(unique_ptr &&) { return *this; }
- template <typename T>
- unique_ptr &operator=(unique_ptr<T> &&) { return *this; }
-
-private:
- type *ptr;
-};
-
-} // namespace std
+#include <memory>
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared-header.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared-header.cpp
index 0e95d070ae55e..65bf830fd3142 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared-header.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared-header.cpp
@@ -2,10 +2,9 @@
// RUN: -config="{CheckOptions: \
// RUN: {modernize-make-shared.MakeSmartPtrFunction: 'my::MakeShared', \
// RUN: modernize-make-shared.MakeSmartPtrFunctionHeader: 'make_shared_util.h' \
-// RUN: }}" \
-// RUN: -- -I %S/Inputs/smart-ptr
+// RUN: }}"
-#include "shared_ptr.h"
+#include <memory>
// CHECK-FIXES: #include "make_shared_util.h"
void f() {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-cxx11.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-cxx11.cpp
index e2944b8080c53..539943e7ba749 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-cxx11.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-cxx11.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -std=c++11 %s modernize-make-unique %t -- -- -I %S/Inputs/smart-ptr
+// RUN: %check_clang_tidy -std=c++11 %s modernize-make-unique %t
-#include "unique_ptr.h"
-// CHECK-FIXES: #include "unique_ptr.h"
+#include <memory>
+// CHECK-FIXES: #include <memory>
void f() {
auto my_ptr = std::unique_ptr<int>(new int(1));
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp
index 50e7beda68a43..aec7189fb2b51 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp
@@ -2,12 +2,10 @@
// RUN: -config="{CheckOptions: \
// RUN: {modernize-make-unique.IgnoreDefaultInitialization: \
// RUN: 'false'}} \
-// RUN: }" \
-// RUN: -- -I %S/Inputs/smart-ptr
+// RUN: }"
-#include "unique_ptr.h"
+#include <memory>
#include <vector>
-// CHECK-FIXES: #include <memory>
void basic() {
std::unique_ptr<int> P1 = std::unique_ptr<int>(new int());
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-header.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-header.cpp
index 5ffd9483a146a..d58f52c06194e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-header.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-header.cpp
@@ -2,10 +2,9 @@
// RUN: -config="{CheckOptions: \
// RUN: {modernize-make-unique.MakeSmartPtrFunction: 'my::MakeUnique', \
// RUN: modernize-make-unique.MakeSmartPtrFunctionHeader: 'make_unique_util.h' \
-// RUN: }}" \
-// RUN: -- -I %S/Inputs/smart-ptr
+// RUN: }}"
-#include "unique_ptr.h"
+#include <memory>
// CHECK-FIXES: #include "make_unique_util.h"
void f() {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-macros.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-macros.cpp
index 78beb911f5a0a..e75daf9938c73 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-macros.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-macros.cpp
@@ -2,7 +2,7 @@
// RUN: -config="{CheckOptions: {modernize-make-unique.IgnoreMacros: false}}" \
// RUN: -- -I %S/Inputs/smart-ptr
-#include "unique_ptr.h"
+#include <memory>
class Foo {};
class Bar {};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp
index 371f3ddf6d650..68c961d92d2dd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp
@@ -1,8 +1,8 @@
-// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- -- -isystem %S/Inputs/replace-auto-ptr
+// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t
// CHECK-FIXES: #include <utility>
-#include "memory.h"
+#include <memory>
// Instrumentation for auto_ptr_ref test.
struct Base {};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
index 7d88c1be24747..bed5c88ed47d8 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -8,6 +8,7 @@
// RUN: '::std::make_pair; ::std::make_tuple; ::test::MakeSingle'}}"
#include <utility>
+#include <memory>
namespace std {
template <typename E>
@@ -313,12 +314,6 @@ tuple<typename remove_reference<Ts>::type...> make_tuple(Ts &&...) {
return {};
}
-template <typename T>
-class unique_ptr {
-public:
- explicit unique_ptr(T *) {}
- ~unique_ptr();
-};
} // namespace std
namespace llvm {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index 21e6c32720163..80b054b74b49a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -6,7 +6,7 @@
// CHECK-FIXES: #include <ranges>
#include "use-ranges/fake_std.h"
-#include "smart-ptr/unique_ptr.h"
+#include <memory>
void Positives() {
std::vector<int> I, J;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call-custom-pointers.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call-custom-pointers.cpp
index df3f16a9cf9ec..679ba48c6d432 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call-custom-pointers.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call-custom-pointers.cpp
@@ -1,10 +1,9 @@
// RUN: %check_clang_tidy %s readability-ambiguous-smartptr-reset-call %t -- \
// RUN: -config='{CheckOptions: \
// RUN: {readability-ambiguous-smartptr-reset-call.SmartPointers: "::std::unique_ptr;::other_ptr"}}' \
-// RUN: --fix-notes -- -I %S/../modernize/Inputs/smart-ptr
+// RUN: --fix-notes
-#include "unique_ptr.h"
-#include "shared_ptr.h"
+#include <memory>
template <typename T>
struct other_ptr {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call.cpp
index e6e7eb9231ec2..1e7bfa0df5e38 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/ambiguous-smartptr-reset-call.cpp
@@ -1,7 +1,6 @@
-// RUN: %check_clang_tidy %s readability-ambiguous-smartptr-reset-call %t --fix-notes -- -I %S/../modernize/Inputs/smart-ptr
+// RUN: %check_clang_tidy %s readability-ambiguous-smartptr-reset-call %t --fix-notes
-#include "unique_ptr.h"
-#include "shared_ptr.h"
+#include <memory>
template <typename T>
struct non_default_reset_ptr {
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 80add8191d323..4fd228a554d7d 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
@@ -4,14 +4,7 @@
#include <string>
#include <type_traits>
#include <vector>
-
-namespace std {
-template <typename T>
-struct unique_ptr {
- T &operator*() const;
- T *operator->() const;
-};
-}
+#include <memory>
template <typename T>
void f(const T *);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index 93dc00845290d..2b8b3261ac765 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -2,6 +2,7 @@
// RUN: -config="{CheckOptions: {readability-container-size-empty.ExcludedComparisonTypes: '::std::array;::IgnoredDummyType'}}" \
// RUN: -- -fno-delayed-template-parsing
#include <string>
+#include <memory>
namespace std {
template <typename T> struct vector {
@@ -682,14 +683,6 @@ void instantiator() {
instantiatedTemplateWithSizeCall<std::vector<int>>();
}
-namespace std {
-template <typename T>
-struct unique_ptr {
- T *operator->() const;
- T &operator*() const;
-};
-} // namespace std
-
bool call_through_unique_ptr(const std::unique_ptr<std::vector<int>> &ptr) {
return ptr->size() > 0;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-macros.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-macros.cpp
index 4c8bb84414355..05b52a67bfc87 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-macros.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-macros.cpp
@@ -1,17 +1,7 @@
// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t -- \
// RUN: -config="{CheckOptions: {readability-redundant-smartptr-get.IgnoreMacros: false}}"
-namespace std {
-
-template <typename T>
-struct shared_ptr {
- T &operator*() const;
- T *operator->() const;
- T *get() const;
- explicit operator bool() const noexcept;
-};
-
-} // namespace std
+#include <memory>
#define MACRO(p) p.get()
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp
index 2d88281eb8524..b74d28f4873bb 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp
@@ -1,42 +1,9 @@
// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t
#include <vector>
+#include <memory>
#define NULL __null
-namespace std {
-
-template <typename T>
-struct unique_ptr {
- T& operator*() const;
- T* operator->() const;
- T* get() const;
- explicit operator bool() const noexcept;
-};
-
-template <typename T>
-struct unique_ptr<T[]> {
- T& operator[](unsigned) const;
- T* get() const;
- explicit operator bool() const noexcept;
-};
-
-template <typename T>
-struct shared_ptr {
- T& operator*() const;
- T* operator->() const;
- T* get() const;
- explicit operator bool() const noexcept;
-};
-
-template <typename T>
-struct shared_ptr<T[]> {
- T& operator[](unsigned) const;
- T* get() const;
- explicit operator bool() const noexcept;
-};
-
-} // namespace std
-
struct Bar {
void Do();
void ConstDo() const;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/uniqueptr-delete-release.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/uniqueptr-delete-release.cpp
index b4695394f6be8..0742b970e7729 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/uniqueptr-delete-release.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/uniqueptr-delete-release.cpp
@@ -1,24 +1,8 @@
// RUN: %check_clang_tidy %s readability-uniqueptr-delete-release %t -check-suffix=NULLPTR
// RUN: %check_clang_tidy %s readability-uniqueptr-delete-release %t -check-suffix=RESET -config='{ \
// RUN: CheckOptions: {readability-uniqueptr-delete-release.PreferResetCall: true}}'
-namespace std {
-template <typename T>
-struct default_delete {};
-
-template <typename T, typename D = default_delete<T>>
-class unique_ptr {
- public:
- unique_ptr();
- ~unique_ptr();
- explicit unique_ptr(T*);
- template <typename U, typename E>
- unique_ptr(unique_ptr<U, E>&&);
- T* release();
- void reset(T *P = nullptr);
- T &operator*() const;
- T *operator->() const;
-};
-} // namespace std
+
+#include <memory>
std::unique_ptr<int>& ReturnsAUnique();
@@ -30,7 +14,7 @@ void Positives() {
// CHECK-FIXES-NULLPTR: P = nullptr;
// CHECK-FIXES-RESET: P.reset();
- auto P2 = P;
+ auto &P2 = P;
delete P2.release();
// CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr' to reset 'unique_ptr<>' objects
// CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()' to reset 'unique_ptr<>' objects
More information about the cfe-commits
mailing list