https://github.com/2LoS created https://github.com/llvm/llvm-project/pull/125719
Fixed `Reference`'s copy and move assignment operators >From 3109461716e5e78b23bea7a2eb6aac3d34348612 Mon Sep 17 00:00:00 2001 From: LoS <aurump...@gmail.com> Date: Mon, 13 Jan 2025 11:21:46 +0100 Subject: [PATCH 1/3] Fixed some warn-override tests in SemaCXX --- ...e => warn-inconsistent-missing-destructor-override.cpp} | 0 ...uctor-override => warn-suggest-destructor-override.cpp} | 0 .../{warn-suggest-override => warn-suggest-override.cpp} | 7 ++++--- 3 files changed, 4 insertions(+), 3 deletions(-) rename clang/test/SemaCXX/{warn-inconsistent-missing-destructor-override => warn-inconsistent-missing-destructor-override.cpp} (100%) rename clang/test/SemaCXX/{warn-suggest-destructor-override => warn-suggest-destructor-override.cpp} (100%) rename clang/test/SemaCXX/{warn-suggest-override => warn-suggest-override.cpp} (58%) 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 e06c939ff001fc..436a17d489693c 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@-1 {{'run()' overrides a member function but is not marked 'override'}} + // expected-warning@-1 {{'run' overrides a member function but is not marked 'override'}} ~D(); }; struct E : public C { virtual void run(); - // expected-warning@-1 {{'run()' overrides a member function but is not marked 'override'}} + // expected-warning@-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@-1 {{class with destructor marked as 'final' can not be inherited from}} }; >From edf5111da4d2b23b25c2902545517f3e3b5eb60c Mon Sep 17 00:00:00 2001 From: LoS <aurump...@gmail.com> Date: Mon, 13 Jan 2025 17:29:35 +0100 Subject: [PATCH 2/3] Cleaned types.pass.cpp tests for sequence containers (libcxx) --- .../containers/sequences/array/types.pass.cpp | 67 ++++++------- .../containers/sequences/deque/types.pass.cpp | 95 ++++++++---------- .../sequences/forwardlist/types.pass.cpp | 84 +++++++++------- .../containers/sequences/list/types.pass.cpp | 80 ++++++++------- .../sequences/vector.bool/types.pass.cpp | 60 ++++++------ .../sequences/vector/types.pass.cpp | 97 +++++++------------ 6 files changed, 229 insertions(+), 254 deletions(-) diff --git a/libcxx/test/std/containers/sequences/array/types.pass.cpp b/libcxx/test/std/containers/sequences/array/types.pass.cpp index c5098105079627..805d82d21ed09c 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 8c14de0c77440a..1d1a5223ee6050 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 116891d4980be9..891b0569d58add 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/sequences/list/types.pass.cpp b/libcxx/test/std/containers/sequences/list/types.pass.cpp index a2d49080f1bcbb..5e8453b89d346b 100644 --- a/libcxx/test/std/containers/sequences/list/types.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/types.pass.cpp @@ -27,6 +27,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 'list'. @@ -47,47 +49,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::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::bidirectional_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::bidirectional_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::list<int> C; - static_assert((std::is_same<C::value_type, int>::value), ""); - static_assert((std::is_same<C::allocator_type, std::allocator<int> >::value), ""); - static_assert((std::is_same<C::reference, std::allocator_traits<std::allocator<int> >::value_type&>::value), ""); - static_assert( - (std::is_same<C::const_reference, const std::allocator_traits<std::allocator<int> >::value_type&>::value), ""); - static_assert((std::is_same<C::pointer, std::allocator_traits<std::allocator<int> >::pointer>::value), ""); - static_assert( - (std::is_same<C::const_pointer, std::allocator_traits<std::allocator<int> >::const_pointer>::value), ""); + typedef std::list<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::allocator_type, Allocator>::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), ""); - } -#if TEST_STD_VER >= 11 - { - typedef std::list<int, min_allocator<int>> C; - static_assert((std::is_same<C::value_type, int>::value), ""); - static_assert((std::is_same<C::allocator_type, min_allocator<int> >::value), ""); - static_assert((std::is_same<C::reference, int&>::value), ""); - static_assert((std::is_same<C::const_reference, const int&>::value), ""); - static_assert((std::is_same<C::pointer, min_pointer<int>>::value), ""); - static_assert((std::is_same<C::const_pointer, min_pointer<const int>>::value), ""); + test_iterators<C>(); +} - 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, 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/sequences/vector.bool/types.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp index d75d7151473521..9480b4f58198c4 100644 --- a/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp @@ -33,54 +33,58 @@ #include "test_macros.h" #include "test_allocator.h" -#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 Allocator> -void -test() +void test() { typedef std::vector<bool, Allocator> C; + typedef std::allocator_traits<Allocator> alloc_traits_t; static_assert((std::is_same<typename C::value_type, bool>::value), ""); static_assert((std::is_same<typename C::value_type, typename 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::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::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), ""); - - 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), ""); + #if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL) static_assert(std::is_same<typename C::const_reference, bool>::value, ""); #endif + + test_iterators<C>(); } int main(int, char**) { - test<test_allocator<bool> >(); - test<std::allocator<bool> >(); - static_assert((std::is_same<std::vector<bool>::allocator_type, - std::allocator<bool> >::value), ""); + test<test_allocator<bool>>(); + #if TEST_STD_VER >= 11 - test<min_allocator<bool> >(); + test<min_allocator<bool>>(); #endif return 0; -} +} \ No newline at end of file diff --git a/libcxx/test/std/containers/sequences/vector/types.pass.cpp b/libcxx/test/std/containers/sequences/vector/types.pass.cpp index f4d7fa088842fc..db11404bb58d5b 100644 --- a/libcxx/test/std/containers/sequences/vector/types.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector/types.pass.cpp @@ -37,82 +37,59 @@ #include "../../Copyable.h" #include "min_allocator.h" -struct A { std::vector<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; + + 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::vector<T, Allocator> C; + typedef std::allocator_traits<Allocator> alloc_traits_t; -// TODO: These tests should use allocator_traits to get stuff, rather than -// blindly pulling typedefs out of the allocator. This is why we can't call -// test<int, min_allocator<int>>() below. 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 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), ""); - 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), ""); + 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::vector<char>::allocator_type, - std::allocator<char> >::value), ""); -#if TEST_STD_VER >= 11 - { + test<double, test_allocator<double>>(); + test<int*, test_allocator<int*>>(); + test<Copyable, test_allocator<Copyable>>(); - typedef std::vector<int, min_allocator<int> > C; - static_assert((std::is_same<C::value_type, int>::value), ""); - static_assert((std::is_same<C::allocator_type, min_allocator<int> >::value), ""); - static_assert((std::is_same<C::reference, int&>::value), ""); - static_assert((std::is_same<C::const_reference, const int&>::value), ""); - static_assert((std::is_same<C::pointer, min_pointer<int>>::value), ""); - static_assert((std::is_same<C::const_pointer, min_pointer<const int>>::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), ""); - } +#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 >From 8cc7463312f6aa786482e34530ea36cc77762cfb Mon Sep 17 00:00:00 2001 From: LoS <aurump...@gmail.com> Date: Tue, 4 Feb 2025 17:58:22 +0100 Subject: [PATCH 3/3] Fixed the 's copy and move assignment operators --- .../robust_against_proxy_iterators_lifetime_bugs.pass.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 c89d6f5a229e8a..e39881a5e5a3ba 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits