From 8a0313d4b6a5dfa2560da46bc5fa4776d0ff8592 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 31 Mar 2016 02:13:14 +0000 Subject: [PATCH] Update container_test_types.h and cleanup the related tests llvm-svn: 264985 --- .../unord/unord.map/max_load_factor.pass.cpp | 5 + .../unord.map/unord.map.elem/index.pass.cpp | 4 + ...nd_emplace_allocator_requirements.pass.cpp | 7 +- .../insert_allocator_requirements.pass.cpp | 7 +- .../insert_allocator_requirements.pass.cpp | 7 +- ...nd_emplace_allocator_requirements.pass.cpp | 7 +- libcxx/test/support/container_test_types.h | 198 +++++++----------- 7 files changed, 92 insertions(+), 143 deletions(-) diff --git a/libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp index b19a6e6cfa08..d9e1d057af03 100644 --- a/libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp @@ -16,6 +16,11 @@ // float max_load_factor() const; // void max_load_factor(float mlf); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + #include #include #include diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp index 4757c926f68f..7bc59447a5e6 100644 --- a/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp @@ -14,6 +14,7 @@ // class unordered_map // mapped_type& operator[](const key_type& k); +// mapped_type& operator[](key_type&& k); #include #include @@ -23,7 +24,10 @@ #include "MoveOnly.h" #include "min_allocator.h" #include "count_new.hpp" + +#if TEST_STD_VER >= 11 #include "container_test_types.h" +#endif int main() { diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_and_emplace_allocator_requirements.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_and_emplace_allocator_requirements.pass.cpp index a7df3e7e48f3..1268051f178e 100644 --- a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_and_emplace_allocator_requirements.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_and_emplace_allocator_requirements.pass.cpp @@ -24,17 +24,12 @@ #include "count_new.hpp" #include "container_test_types.h" -#if TEST_STD_VER >= 11 template void PrintInfo(int line, Arg&& arg) -#else -template -void PrintInfo(int line, Arg arg) -#endif { std::cout << "In " << __FILE__ << ":" << line << ":\n " << arg << "\n" << std::endl; } -#define PRINT(...) PrintInfo(__LINE__, __VA_ARGS__) +#define PRINT(msg) PrintInfo(__LINE__, msg) template void testContainerInsert() diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_allocator_requirements.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_allocator_requirements.pass.cpp index 0926e8057cab..793419a6580c 100644 --- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_allocator_requirements.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_allocator_requirements.pass.cpp @@ -23,17 +23,12 @@ #include "count_new.hpp" #include "container_test_types.h" -#if TEST_STD_VER >= 11 template void PrintInfo(int line, Arg&& arg) -#else -template -void PrintInfo(int line, Arg arg) -#endif { std::cout << "In " << __FILE__ << ":" << line << ":\n " << arg << "\n" << std::endl; } -#define PRINT(...) PrintInfo(__LINE__, __VA_ARGS__) +#define PRINT(msg) PrintInfo(__LINE__, msg) template void testContainerInsert() diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_allocator_requirements.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_allocator_requirements.pass.cpp index ae8ce0559104..791d7dd46045 100644 --- a/libcxx/test/std/containers/unord/unord.multiset/insert_allocator_requirements.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.multiset/insert_allocator_requirements.pass.cpp @@ -23,17 +23,12 @@ #include "count_new.hpp" #include "container_test_types.h" -#if TEST_STD_VER >= 11 template void PrintInfo(int line, Arg&& arg) -#else -template -void PrintInfo(int line, Arg arg) -#endif { std::cout << "In " << __FILE__ << ":" << line << ":\n " << arg << "\n" << std::endl; } -#define PRINT(...) PrintInfo(__LINE__, __VA_ARGS__) +#define PRINT(msg) PrintInfo(__LINE__, msg) template void testContainerInsert() diff --git a/libcxx/test/std/containers/unord/unord.set/insert_and_emplace_allocator_requirements.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_and_emplace_allocator_requirements.pass.cpp index 14e08927cc24..05c2d0a0bc4c 100644 --- a/libcxx/test/std/containers/unord/unord.set/insert_and_emplace_allocator_requirements.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.set/insert_and_emplace_allocator_requirements.pass.cpp @@ -24,17 +24,12 @@ #include "count_new.hpp" #include "container_test_types.h" -#if TEST_STD_VER >= 11 template void PrintInfo(int line, Arg&& arg) -#else -template -void PrintInfo(int line, Arg arg) -#endif { std::cout << "In " << __FILE__ << ":" << line << ":\n " << arg << "\n" << std::endl; } -#define PRINT(...) PrintInfo(__LINE__, __VA_ARGS__) +#define PRINT(msg) PrintInfo(__LINE__, msg) template void testContainerInsert() diff --git a/libcxx/test/support/container_test_types.h b/libcxx/test/support/container_test_types.h index 7c9dee085028..7a3f5acf21d5 100644 --- a/libcxx/test/support/container_test_types.h +++ b/libcxx/test/support/container_test_types.h @@ -86,12 +86,14 @@ */ #include -#include -#include #include #include "test_macros.h" +#if TEST_STD_VER < 11 +#error This header requires C++11 or greater +#endif + namespace detail { // TypeID - Represent a unique identifier for a type. TypeID allows equality // comparisons between different types. @@ -101,7 +103,7 @@ struct TypeID { friend bool operator!=(TypeID const& LHS, TypeID const& RHS) {return LHS.m_id != RHS.m_id; } private: - explicit TEST_CONSTEXPR TypeID(const int* xid) : m_id(xid) {} + explicit constexpr TypeID(const int* xid) : m_id(xid) {} const int* const m_id; template friend class TypeInfo; }; @@ -132,37 +134,17 @@ const int TypeInfo::dummy_addr = 42; // makeTypeID - Return the TypeID for the specified type 'T'. template -inline TEST_CONSTEXPR TypeID const& makeTypeID() { return TypeInfo::GetID(); } +inline constexpr TypeID const& makeTypeID() { return TypeInfo::GetID(); } -#if TEST_STD_VER >= 11 template struct ArgumentListID {}; // makeArgumentID - Create and return a unique identifier for a given set // of arguments. template -inline TEST_CONSTEXPR TypeID const& makeArgumentID() { +inline constexpr TypeID const& makeArgumentID() { return makeTypeID>(); } -#else -template -struct ArgumentListID {}; - -template -inline TypeID const& makeArgumentID() { - return makeTypeID >(); -} - -template -inline TypeID const& makeArgumentID() { - return makeTypeID >(); -} - -template -inline TypeID const& makeArgumentID() { - return makeTypeID >(); -} -#endif } // namespace detail @@ -199,7 +181,6 @@ struct AllocatorConstructController { m_expected_args = &tid; } -#if TEST_STD_VER >= 11 template void expect(int times = 1) { assert(!unchecked()); @@ -211,19 +192,7 @@ struct AllocatorConstructController { bool check() { return check(detail::makeArgumentID()); } -#else - template - void expect(int times = 1) { - assert(!unchecked()); - assert(times > 0); - m_expected_count = times - 1; - m_expected_args = &detail::makeArgumentID(); - } - template - bool check() { - return check(detail::makeArgumentID()); - } -#endif + // Return true iff the program is currently within a call to "Allocator::construct" bool isInAllocatorConstruct() const { @@ -315,7 +284,7 @@ public: { return ::operator delete(static_cast(p)); } -#if TEST_STD_VER >= 11 + template void construct(Up* p, Args&&... args) { static_assert((std::is_same::value), @@ -326,28 +295,6 @@ public: ::new ((void*)p) Up(std::forward(args)...); } } -#else - template - void construct(Up* p, A0& a0) { - static_assert((std::is_same::value), - "Only allowed to construct Up"); - assert(controller->check()); - { - InAllocatorConstructGuard g(controller); - ::new ((void*)p) Up(a0); - } - } - template - void construct(Up* p, A0& a0, A1& a1) { - static_assert((std::is_same::value), - "Only allowed to construct Up"); - assert((controller->check())); - { - InAllocatorConstructGuard g(controller); - ::new ((void*)p) Up(a0, a1); - } - } -#endif template void destroy(Up* p) { @@ -363,7 +310,7 @@ public: friend bool operator!=(ContainerTestAllocator x, ContainerTestAllocator y) {return !(x == y);} }; -#if TEST_STD_VER >= 11 + namespace test_detail { typedef ContainerTestAllocator A1; typedef std::allocator_traits A1T; @@ -373,7 +320,6 @@ typedef std::allocator_traits A2T; static_assert(std::is_same, A2T>::value, ""); static_assert(std::is_same, A1T>::value, ""); } // end namespace test_detail -#endif //===----------------------------------------------------------------------===// // 'CopyInsertable', 'MoveInsertable' and 'EmplaceConstructible' test types @@ -413,7 +359,6 @@ struct CopyInsertable { other.copied_once = true; } -#if TEST_STD_VER >= 11 CopyInsertable(CopyInsertable&& other) : CopyInsertable(other) {} // Forgive pair for not downcasting this to an lvalue it its constructors. @@ -424,12 +369,6 @@ struct CopyInsertable { CopyInsertable(Args&&... args) { assert(false); } -#else - template - CopyInsertable(Arg&) { - assert(false); - } -#endif ~CopyInsertable() { assert(constructed_under_allocator == getConstructController()->isInAllocatorConstruct()); @@ -458,68 +397,89 @@ bool operator <(CopyInsertable const& L, CopyInsertable const& R) { return L.data < R.data; } -namespace std { -template -struct hash< ::CopyInsertable > { - typedef ::CopyInsertable argument_type; - typedef size_t result_type; - size_t operator()(argument_type const& arg) const { - return arg.data; - } -}; -} // namespace std +#ifdef _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_NAMESPACE_STD +#else +namespace std { +#endif + template + struct hash< ::CopyInsertable > { + typedef ::CopyInsertable argument_type; + typedef size_t result_type; + + size_t operator()(argument_type const& arg) const { + return arg.data; + } + }; + + template + class map; + template + class multimap; + template + class set; + template + class multiset; + template + class unordered_map; + template + class unordered_multimap; + template + class unordered_set; + template + class unordered_multiset; + +#ifdef _LIBCPP_END_NAMESPACE_STD +_LIBCPP_END_NAMESPACE_STD +#else +} // end namespace std +#endif // TCT - Test container type namespace TCT { -template , class Value = CopyInsertable<2> > -struct unordered_map_type { - typedef std::pair ValueTp; - typedef +template , class Value = CopyInsertable<2>, + class ValueTp = std::pair > +using unordered_map = std::unordered_map, std::equal_to, - ContainerTestAllocator > - type; -}; + ContainerTestAllocator >; -template , class Value = CopyInsertable<2> > -struct unordered_multimap_type { - typedef std::pair ValueTp; - typedef +template , class Value = CopyInsertable<2>, + class ValueTp = std::pair > +using map = + std::map, + ContainerTestAllocator >; + +template , class Value = CopyInsertable<2>, + class ValueTp = std::pair > +using unordered_multimap = std::unordered_multimap, std::equal_to, - ContainerTestAllocator > - type; -}; + ContainerTestAllocator >; + +template , class Value = CopyInsertable<2>, + class ValueTp = std::pair > +using multimap = + std::multimap, + ContainerTestAllocator >; template > -struct unordered_set_type { - typedef - std::unordered_set, std::equal_to, - ContainerTestAllocator > - type; -}; +using unordered_set = + std::unordered_set, std::equal_to, + ContainerTestAllocator >; template > -struct unordered_multiset_type { - typedef +using set = + std::set, ContainerTestAllocator >; + +template > +using unordered_multiset = std::unordered_multiset, std::equal_to, - ContainerTestAllocator > - type; -}; + ContainerTestAllocator >; -#if TEST_STD_VER >= 11 -template -using unordered_map = typename unordered_map_type::type; - -template -using unordered_multimap = typename unordered_multimap_type::type; - -template -using unordered_set = typename unordered_set_type::type; - -template -using unordered_multiset = typename unordered_multiset_type::type; -#endif +template > +using multiset = + std::multiset, ContainerTestAllocator >; } // end namespace TCT