[libcxx-commits] [clang] [libcxx] Proxy ref (PR #125719)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 4 08:58:50 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: LoS (2LoS)

<details>
<summary>Changes</summary>

Fixed `Reference`'s copy and move assignment operators

---

Patch is 36.65 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/125719.diff


10 Files Affected:

- (renamed) clang/test/SemaCXX/warn-inconsistent-missing-destructor-override.cpp () 
- (renamed) clang/test/SemaCXX/warn-suggest-destructor-override.cpp () 
- (renamed) clang/test/SemaCXX/warn-suggest-override.cpp (+4-3) 
- (modified) libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp (+3-3) 
- (modified) libcxx/test/std/containers/sequences/array/types.pass.cpp (+29-38) 
- (modified) libcxx/test/std/containers/sequences/deque/types.pass.cpp (+38-57) 
- (modified) libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp (+47-37) 
- (modified) libcxx/test/std/containers/sequences/list/types.pass.cpp (+46-34) 
- (modified) libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp (+32-28) 
- (modified) libcxx/test/std/containers/sequences/vector/types.pass.cpp (+37-60) 


``````````diff
diff --git a/clang/test/SemaCXX/warn-inconsistent-missing-destructor-override b/clang/test/SemaCXX/warn-inconsistent-missing-destructor-override.cpp
similarity index 100%
rename from clang/test/SemaCXX/warn-inconsistent-missing-destructor-override
rename to clang/test/SemaCXX/warn-inconsistent-missing-destructor-override.cpp
diff --git a/clang/test/SemaCXX/warn-suggest-destructor-override b/clang/test/SemaCXX/warn-suggest-destructor-override.cpp
similarity index 100%
rename from clang/test/SemaCXX/warn-suggest-destructor-override
rename to clang/test/SemaCXX/warn-suggest-destructor-override.cpp
diff --git a/clang/test/SemaCXX/warn-suggest-override b/clang/test/SemaCXX/warn-suggest-override.cpp
similarity index 58%
rename from clang/test/SemaCXX/warn-suggest-override
rename to clang/test/SemaCXX/warn-suggest-override.cpp
index e06c939ff001fc9..436a17d489693c3 100644
--- a/clang/test/SemaCXX/warn-suggest-override
+++ b/clang/test/SemaCXX/warn-suggest-override.cpp
@@ -17,13 +17,13 @@ struct C {
 
 struct D : public C {
   void run();
-  // expected-warning at -1 {{'run()' overrides a member function but is not marked 'override'}}
+  // expected-warning at -1 {{'run' overrides a member function but is not marked 'override'}}
   ~D();
 };
 
 struct E : public C {
   virtual void run();
-  // expected-warning at -1 {{'run()' overrides a member function but is not marked 'override'}}
+  // expected-warning at -1 {{'run' overrides a member function but is not marked 'override'}}
   virtual ~E();
 };
 
@@ -32,7 +32,8 @@ struct F : public C {
   ~F() override;
 };
 
-struct G : public C {
+struct G : public C { // expected-note {{mark 'G' as 'final'}}
   void run() final;
   ~G() final;
+  // expected-warning at -1 {{class with destructor marked as 'final' can not be inherited from}}
 };
diff --git a/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp b/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp
index c89d6f5a229e8ad..e39881a5e5a3ba1 100644
--- a/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp
+++ b/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp
@@ -159,7 +159,7 @@ class LifetimeIterator {
       assert(!rhs.moved_from_);
       rhs.moved_from_ = true;
 
-      *v_ = *rhs.v_;
+      *v_ = std::move(*rhs.v_);
       moved_from_ = false;
 
       return *this;
@@ -368,7 +368,7 @@ class ConstexprIterator {
     constexpr Reference(const Reference& rhs) = default;
     constexpr Reference& operator=(const Reference& rhs) {
       assert(!rhs.moved_from_);
-      v_ = rhs.v_;
+      *v_ = *rhs.v_;
       moved_from_ = false;
 
       return *this;
@@ -384,7 +384,7 @@ class ConstexprIterator {
       rhs.moved_from_ = true;
       moved_from_ = false;
 
-      v_ = rhs.v_;
+      *v_ = std::move(*rhs.v_);
       return *this;
     }
 
diff --git a/libcxx/test/std/containers/sequences/array/types.pass.cpp b/libcxx/test/std/containers/sequences/array/types.pass.cpp
index c50981050796275..805d82d21ed09c8 100644
--- a/libcxx/test/std/containers/sequences/array/types.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/types.pass.cpp
@@ -28,12 +28,15 @@
 #include <iterator>
 #include <type_traits>
 
+#include "../../Copyable.h"
 #include "test_macros.h"
 
 template <class C>
-void test_iterators() {
+void test_iterators()
+{
     typedef std::iterator_traits<typename C::iterator> ItT;
     typedef std::iterator_traits<typename C::const_iterator> CItT;
+
     static_assert((std::is_same<typename ItT::iterator_category, std::random_access_iterator_tag>::value), "");
     static_assert((std::is_same<typename ItT::value_type, typename C::value_type>::value), "");
     static_assert((std::is_same<typename ItT::reference, typename C::reference>::value), "");
@@ -47,48 +50,36 @@ void test_iterators() {
     static_assert((std::is_same<typename CItT::difference_type, typename C::difference_type>::value), "");
 }
 
-int main(int, char**)
+template <class T, std::size_t N>
+void test()
 {
-    {
-        typedef double T;
-        typedef std::array<T, 10> C;
-        static_assert((std::is_same<C::reference, T&>::value), "");
-        static_assert((std::is_same<C::const_reference, const T&>::value), "");
-        test_iterators<C>();
-        static_assert((std::is_same<C::pointer, T*>::value), "");
-        static_assert((std::is_same<C::const_pointer, const T*>::value), "");
-        static_assert((std::is_same<C::size_type, std::size_t>::value), "");
-        static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
-        static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), "");
-        static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), "");
+        typedef std::array<T, N> C;
+
+		static_assert((std::is_same<typename C::value_type, T>::value), "");
+        static_assert((std::is_same<typename C::reference, T&>::value), "");
+        static_assert((std::is_same<typename C::const_reference, const T&>::value), "");
+        static_assert((std::is_same<typename C::pointer, T*>::value), "");
+        static_assert((std::is_same<typename C::const_pointer, const T*>::value), "");
+        static_assert((std::is_same<typename C::size_type, std::size_t>::value), "");
+        static_assert((std::is_same<typename C::difference_type, std::ptrdiff_t>::value), "");
+        static_assert((std::is_same<typename C::reverse_iterator, std::reverse_iterator<typename C::iterator> >::value), "");
+        static_assert((std::is_same<typename C::const_reverse_iterator, std::reverse_iterator<typename C::const_iterator> >::value), "");
 
         static_assert((std::is_signed<typename C::difference_type>::value), "");
         static_assert((std::is_unsigned<typename C::size_type>::value), "");
-        static_assert((std::is_same<typename C::difference_type,
-            typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
-        static_assert((std::is_same<typename C::difference_type,
-            typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
-    }
-    {
-        typedef int* T;
-        typedef std::array<T, 0> C;
-        static_assert((std::is_same<C::reference, T&>::value), "");
-        static_assert((std::is_same<C::const_reference, const T&>::value), "");
+
         test_iterators<C>();
-        static_assert((std::is_same<C::pointer, T*>::value), "");
-        static_assert((std::is_same<C::const_pointer, const T*>::value), "");
-        static_assert((std::is_same<C::size_type, std::size_t>::value), "");
-        static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
-        static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), "");
-        static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), "");
+}
 
-        static_assert((std::is_signed<typename C::difference_type>::value), "");
-        static_assert((std::is_unsigned<typename C::size_type>::value), "");
-        static_assert((std::is_same<typename C::difference_type,
-            typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
-        static_assert((std::is_same<typename C::difference_type,
-            typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
-    }
+int main(int, char**)
+{
+    test<double, 10>();
+    test<int*, 10>();
+    test<Copyable, 10>();
+
+    test<double, 0>();
+    test<int*, 0>();
+    test<Copyable, 0>();
 
   return 0;
-}
+}
\ No newline at end of file
diff --git a/libcxx/test/std/containers/sequences/deque/types.pass.cpp b/libcxx/test/std/containers/sequences/deque/types.pass.cpp
index 8c14de0c77440a5..1d1a5223ee6050a 100644
--- a/libcxx/test/std/containers/sequences/deque/types.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/types.pass.cpp
@@ -37,77 +37,58 @@
 #include "../../Copyable.h"
 #include "min_allocator.h"
 
+template <class C>
+void test_iterators()
+{
+    typedef std::iterator_traits<typename C::iterator> ItT;
+    typedef std::iterator_traits<typename C::const_iterator> CItT;
+
+    static_assert((std::is_same<typename ItT::iterator_category, std::random_access_iterator_tag>::value), "");
+    static_assert((std::is_same<typename ItT::value_type, typename C::value_type>::value), "");
+    static_assert((std::is_same<typename ItT::reference, typename C::reference>::value), "");
+    static_assert((std::is_same<typename ItT::pointer, typename C::pointer>::value), "");
+    static_assert((std::is_same<typename ItT::difference_type, typename C::difference_type>::value), "");
+
+    static_assert((std::is_same<typename CItT::iterator_category, std::random_access_iterator_tag>::value), "");
+    static_assert((std::is_same<typename CItT::value_type, typename C::value_type>::value), "");
+    static_assert((std::is_same<typename CItT::reference, typename C::const_reference>::value), "");
+    static_assert((std::is_same<typename CItT::pointer, typename C::const_pointer>::value), "");
+    static_assert((std::is_same<typename CItT::difference_type, typename C::difference_type>::value), "");
+}
+
 template <class T, class Allocator>
-void
-test()
+void test()
 {
     typedef std::deque<T, Allocator> C;
+    typedef std::allocator_traits<Allocator> alloc_traits_t;
 
     static_assert((std::is_same<typename C::value_type, T>::value), "");
-    static_assert(
-        (std::is_same<typename C::value_type, typename std::allocator_traits<Allocator>::value_type>::value), "");
     static_assert((std::is_same<typename C::allocator_type, Allocator>::value), "");
-    static_assert(
-        (std::is_same<typename C::size_type, typename std::allocator_traits<Allocator>::size_type>::value), "");
-    static_assert(
-        (std::is_same<typename C::difference_type, typename std::allocator_traits<Allocator>::difference_type>::value),
-        "");
-    static_assert(
-        (std::is_same<typename C::reference, typename std::allocator_traits<Allocator>::value_type&>::value), "");
-    static_assert((std::is_same<typename C::const_reference,
-                                const typename std::allocator_traits<Allocator>::value_type&>::value),
-                  "");
-    static_assert((std::is_same<typename C::pointer, typename std::allocator_traits<Allocator>::pointer>::value), "");
-    static_assert(
-        (std::is_same<typename C::const_pointer, typename std::allocator_traits<Allocator>::const_pointer>::value), "");
-    static_assert((std::is_same<
-        typename std::iterator_traits<typename C::iterator>::iterator_category,
-        std::random_access_iterator_tag>::value), "");
-    static_assert((std::is_same<
-        typename std::iterator_traits<typename C::const_iterator>::iterator_category,
-        std::random_access_iterator_tag>::value), "");
-    static_assert((std::is_same<
-        typename C::reverse_iterator,
-        std::reverse_iterator<typename C::iterator> >::value), "");
-    static_assert((std::is_same<
-        typename C::const_reverse_iterator,
-        std::reverse_iterator<typename C::const_iterator> >::value), "");
+    static_assert((std::is_same<typename C::size_type, typename alloc_traits_t::size_type>::value), "");
+    static_assert((std::is_same<typename C::difference_type, typename alloc_traits_t::difference_type>::value), "");
+    static_assert((std::is_same<typename C::reference, T&>::value), "");
+    static_assert((std::is_same<typename C::const_reference, const T&>::value), "");
+    static_assert((std::is_same<typename C::pointer, typename alloc_traits_t::pointer>::value), "");
+    static_assert((std::is_same<typename C::const_pointer, typename alloc_traits_t::const_pointer>::value), "");
+    static_assert((std::is_same<typename C::reverse_iterator, std::reverse_iterator<typename C::iterator> >::value), "");
+    static_assert((std::is_same<typename C::const_reverse_iterator, std::reverse_iterator<typename C::const_iterator> >::value), "");
+
     static_assert((std::is_signed<typename C::difference_type>::value), "");
     static_assert((std::is_unsigned<typename C::size_type>::value), "");
-    static_assert((std::is_same<typename C::difference_type,
-        typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
-    static_assert((std::is_same<typename C::difference_type,
-        typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
+
+	test_iterators<C>();
 }
 
 int main(int, char**)
 {
-    test<int, test_allocator<int> >();
-    test<int*, std::allocator<int*> >();
-    test<Copyable, test_allocator<Copyable> >();
-    static_assert((std::is_same<std::deque<char>::allocator_type,
-                                std::allocator<char> >::value), "");
+    test<double, test_allocator<double>>();
+    test<int*, test_allocator<int*>>();
+    test<Copyable, test_allocator<Copyable>>();
 
 #if TEST_STD_VER >= 11
-    {
-        typedef std::deque<short, min_allocator<short>> C;
-        static_assert((std::is_same<C::value_type, short>::value), "");
-        static_assert((std::is_same<C::allocator_type, min_allocator<C::value_type> >::value), "");
-        static_assert((std::is_same<C::reference, C::value_type&>::value), "");
-        static_assert((std::is_same<C::const_reference, const C::value_type&>::value), "");
-        static_assert((std::is_same<C::pointer, min_pointer<C::value_type>>::value), "");
-        static_assert((std::is_same<C::const_pointer, min_pointer<const C::value_type>>::value), "");
-//  min_allocator doesn't have a size_type, so one gets synthesized
-        static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), "");
-        static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
-
-        static_assert((std::is_signed<typename C::difference_type>::value), "");
-        static_assert((std::is_unsigned<typename C::size_type>::value), "");
-        static_assert((std::is_same<typename C::difference_type,
-            typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
-        static_assert((std::is_same<typename C::difference_type,
-            typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
-    }
+	test<double, min_allocator<double>>();
+    test<int*, min_allocator<int*>>();
+    test<Copyable, min_allocator<Copyable>>();
 #endif
 
   return 0;
diff --git a/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp
index 116891d4980be9c..891b0569d58add3 100644
--- a/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp
+++ b/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp
@@ -30,6 +30,8 @@
 #include <type_traits>
 
 #include "test_macros.h"
+#include "test_allocator.h"
+#include "../../Copyable.h"
 #include "min_allocator.h"
 
 // Ensures that we don't use a non-uglified name 'base' in the implementation of 'forward_list'.
@@ -50,49 +52,57 @@ static_assert(std::is_same<my_derived<int, min_allocator<int>>::base, my_base>::
 static_assert(std::is_same<my_derived<my_base, min_allocator<my_base>>::base, my_base>::value, "");
 #endif
 
-struct A { std::forward_list<A> v; }; // incomplete type support
+template <class C>
+void test_iterators()
+{
+    typedef std::iterator_traits<typename C::iterator> ItT;
+    typedef std::iterator_traits<typename C::const_iterator> CItT;
 
-int main(int, char**)
+    static_assert((std::is_same<typename ItT::iterator_category, std::forward_iterator_tag>::value), "");
+    static_assert((std::is_same<typename ItT::value_type, typename C::value_type>::value), "");
+    static_assert((std::is_same<typename ItT::reference, typename C::reference>::value), "");
+    static_assert((std::is_same<typename ItT::pointer, typename C::pointer>::value), "");
+    static_assert((std::is_same<typename ItT::difference_type, typename C::difference_type>::value), "");
+
+    static_assert((std::is_same<typename CItT::iterator_category, std::forward_iterator_tag>::value), "");
+    static_assert((std::is_same<typename CItT::value_type, typename C::value_type>::value), "");
+    static_assert((std::is_same<typename CItT::reference, typename C::const_reference>::value), "");
+    static_assert((std::is_same<typename CItT::pointer, typename C::const_pointer>::value), "");
+    static_assert((std::is_same<typename CItT::difference_type, typename C::difference_type>::value), "");
+}
+
+template <class T, class Allocator>
+void test()
 {
-    {
-    typedef std::forward_list<char> C;
-    static_assert((std::is_same<C::value_type, char>::value), "");
-    static_assert((std::is_same<C::allocator_type, std::allocator<char> >::value), "");
-    static_assert((std::is_same<C::reference, char&>::value), "");
-    static_assert((std::is_same<C::const_reference, const char&>::value), "");
-    static_assert((std::is_same<C::pointer, char*>::value), "");
-    static_assert((std::is_same<C::const_pointer, const char*>::value), "");
-    static_assert((std::is_same<C::size_type, std::size_t>::value), "");
-    static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
+    typedef std::forward_list<T, Allocator> C;
+	typedef std::allocator_traits<Allocator> alloc_traits_t;
 
-    static_assert((std::is_signed<typename C::difference_type>::value), "");
-    static_assert((std::is_unsigned<typename C::size_type>::value), "");
-    static_assert((std::is_same<typename C::difference_type,
-        typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
-    static_assert((std::is_same<typename C::difference_type,
-        typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
-    }
-#if TEST_STD_VER >= 11
-    {
-    typedef std::forward_list<char, min_allocator<char>> C;
-    static_assert((std::is_same<C::value_type, char>::value), "");
-    static_assert((std::is_same<C::allocator_type, min_allocator<char> >::value), "");
-    static_assert((std::is_same<C::reference, char&>::value), "");
-    static_assert((std::is_same<C::const_reference, const char&>::value), "");
-    static_assert((std::is_same<C::pointer, min_pointer<char>>::value), "");
-    static_assert((std::is_same<C::const_pointer, min_pointer<const char>>::value), "");
-//  min_allocator doesn't have a size_type, so one gets synthesized
-    static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), "");
-    static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
+    static_assert((std::is_same<C::value_type, T>::value), "");
+    static_assert((std::is_same<C::allocator_type, Allocator>::value), "");
+    static_assert((std::is_same<C::reference, T&>::value), "");
+    static_assert((std::is_same<C::const_reference, const T&>::value), "");
+    static_assert((std::is_same<C::pointer, typename alloc_traits_t::pointer>::value), "");
+    static_assert((std::is_same<C::const_pointer, typename alloc_traits_t::const_pointer>::value), "");
+    static_assert((std::is_same<C::size_type, typename alloc_traits_t::size_type>::value), "");
+    static_assert((std::is_same<C::difference_type, typename alloc_traits_t::difference_type>::value), "");
 
     static_assert((std::is_signed<typename C::difference_type>::value), "");
     static_assert((std::is_unsigned<typename C::size_type>::value), "");
-    static_assert((std::is_same<typename C::difference_type,
-        typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
-    static_assert((std::is_same<typename C::difference_type,
-        typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
-    }
+
+	test_iterators<C>();
+}
+
+int main(int, char**)
+{
+	test<double, test_allocator<double>>();
+    test<int, test_allocator<int>>();
+    test<Copyable, test_allocator<Copyable>>();
+
+#if TEST_STD_VER >= 11
+	test<double, min_allocator<double>>();
+    test<int*, min_allocator<int*>>();
+    test<Copyable, min_allocator<Copyable>>();
 #endif
 
   return 0;
-}
+}
\ No newline at end of file
diff --git a/libcxx/test/std/containers...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/125719


More information about the libcxx-commits mailing list