diff --git a/test/sources/libcxx/map/map.access/at.pass.cpp b/test/sources/libcxx/map/map.access/at.pass.cpp index 0b3517ecf..b072121b2 100644 --- a/test/sources/libcxx/map/map.access/at.pass.cpp +++ b/test/sources/libcxx/map/map.access/at.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -11,7 +10,6 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions // // class map @@ -19,12 +17,7 @@ // mapped_type& at(const key_type& k); // const mapped_type& at(const key_type& k) const; -//#include -//#include - -//#include "min_allocator.h" - -void main() +int main(int, char**) { { typedef std::pair V; @@ -38,7 +31,7 @@ void main() V(7, 7.5), V(8, 8.5), }; - map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); assert(m.size() == 7); assert(m.at(1) == 1.5); m.at(1) = -1.5; @@ -47,14 +40,16 @@ void main() assert(m.at(3) == 3.5); assert(m.at(4) == 4.5); assert(m.at(5) == 5.5); +#ifndef TEST_HAS_NO_EXCEPTIONS try { - m.at(6); + TEST_IGNORE_NODISCARD m.at(6); assert(false); } catch (std::out_of_range&) { } +#endif assert(m.at(7) == 7.5); assert(m.at(8) == 8.5); assert(m.size() == 7); @@ -71,27 +66,28 @@ void main() V(7, 7.5), V(8, 8.5), }; - const map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + const std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); assert(m.size() == 7); assert(m.at(1) == 1.5); assert(m.at(2) == 2.5); assert(m.at(3) == 3.5); assert(m.at(4) == 4.5); assert(m.at(5) == 5.5); +#ifndef TEST_HAS_NO_EXCEPTIONS try { - m.at(6); + TEST_IGNORE_NODISCARD m.at(6); assert(false); } catch (std::out_of_range&) { } +#endif assert(m.at(7) == 7.5); assert(m.at(8) == 8.5); assert(m.size() == 7); } -//#if __cplusplus >= 201103L -#ifdef LIBCPP_TEST_MIN_ALLOCATOR +#if TEST_STD_VER >= 11 { typedef std::pair V; V ar[] = @@ -104,7 +100,7 @@ void main() V(7, 7.5), V(8, 8.5), }; - map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); assert(m.size() == 7); assert(m.at(1) == 1.5); m.at(1) = -1.5; @@ -113,14 +109,16 @@ void main() assert(m.at(3) == 3.5); assert(m.at(4) == 4.5); assert(m.at(5) == 5.5); +#ifndef TEST_HAS_NO_EXCEPTIONS try { - m.at(6); + TEST_IGNORE_NODISCARD m.at(6); assert(false); } catch (std::out_of_range&) { } +#endif assert(m.at(7) == 7.5); assert(m.at(8) == 8.5); assert(m.size() == 7); @@ -137,24 +135,28 @@ void main() V(7, 7.5), V(8, 8.5), }; - const map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + const std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); assert(m.size() == 7); assert(m.at(1) == 1.5); assert(m.at(2) == 2.5); assert(m.at(3) == 3.5); assert(m.at(4) == 4.5); assert(m.at(5) == 5.5); +#ifndef TEST_HAS_NO_EXCEPTIONS try { - m.at(6); + TEST_IGNORE_NODISCARD m.at(6); assert(false); } catch (std::out_of_range&) { } +#endif assert(m.at(7) == 7.5); assert(m.at(8) == 8.5); assert(m.size() == 7); } #endif + + return 0; } diff --git a/test/sources/libcxx/map/map.access/empty.pass.cpp b/test/sources/libcxx/map/map.access/empty.pass.cpp index 69b8816a3..fc3cf279c 100644 --- a/test/sources/libcxx/map/map.access/empty.pass.cpp +++ b/test/sources/libcxx/map/map.access/empty.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -17,15 +16,10 @@ // bool empty() const; -//#include -//#include - -//#include "min_allocator.h" - -void main() +int main(int, char**) { { - typedef map M; + typedef std::map M; M m; assert(m.empty()); m.insert(M::value_type(1, 1.5)); @@ -33,10 +27,9 @@ void main() m.clear(); assert(m.empty()); } -//#if __cplusplus >= 201103L -#ifdef LIBCPP_TEST_MIN_ALLOCATOR +#if TEST_STD_VER >= 11 { - typedef map, min_allocator>> M; + typedef std::map, min_allocator>> M; M m; assert(m.empty()); m.insert(M::value_type(1, 1.5)); @@ -45,4 +38,6 @@ void main() assert(m.empty()); } #endif + + return 0; } diff --git a/test/sources/libcxx/map/map.access/index_key.pass.cpp b/test/sources/libcxx/map/map.access/index_key.pass.cpp index bf9e34e67..04b85ee3b 100644 --- a/test/sources/libcxx/map/map.access/index_key.pass.cpp +++ b/test/sources/libcxx/map/map.access/index_key.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -17,13 +16,15 @@ // mapped_type& operator[](const key_type& k); -//#include -//#include - -//#include "min_allocator.h" -//#include "private_constructor.hpp" +namespace TCT { +template , class Value = CopyInsertable<2>, + class ValueTp = std::pair > +using map = + std::map, + ContainerTestAllocator >; +} -void main() +int main(int, char**) { { typedef std::pair V; @@ -37,7 +38,7 @@ void main() V(7, 7.5), V(8, 8.5), }; - map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); assert(m.size() == 7); assert(m[1] == 1.5); assert(m.size() == 7); @@ -52,8 +53,7 @@ void main() assert(m[6] == 6.5); assert(m.size() == 8); } -//#if __cplusplus >= 201103L -#ifdef LIBCPP_TEST_MIN_ALLOCATOR +#if TEST_STD_VER >= 11 { typedef std::pair V; V ar[] = @@ -66,7 +66,7 @@ void main() V(7, 7.5), V(8, 8.5), }; - map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); assert(m.size() == 7); assert(m[1] == 1.5); assert(m.size() == 7); @@ -80,9 +80,43 @@ void main() assert(m[6] == 6.5); assert(m.size() == 8); } +#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO + { + // Use "container_test_types.h" to check what arguments get passed + // to the allocator for operator[] + using Container = TCT::map<>; + using Key = Container::key_type; + using MappedType = Container::mapped_type; + ConstructController* cc = getConstructController(); + cc->reset(); + { + Container c; + const Key k(1); + cc->expect&&, std::tuple<>&&>(); + MappedType& mref = c[k]; + assert(!cc->unchecked()); + { + DisableAllocationGuard g; + MappedType& mref2 = c[k]; + assert(&mref == &mref2); + } + } + { + Container c; + Key k(1); + cc->expect&&, std::tuple<>&&>(); + MappedType& mref = c[k]; + assert(!cc->unchecked()); + { + DisableAllocationGuard g; + MappedType& mref2 = c[k]; + assert(&mref == &mref2); + } + } + } #endif -//#if _LIBCPP_STD_VER > 11 -#ifndef LIBCPP_HAS_NO_TRANSPARENT_OPERATORS +#endif +#if TEST_STD_VER > 11 { typedef std::pair V; V ar[] = @@ -95,7 +129,7 @@ void main() V(7, 7.5), V(8, 8.5), }; - map> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::map> m(ar, ar+sizeof(ar)/sizeof(ar[0])); assert(m.size() == 7); assert(m[1] == 1.5); @@ -103,13 +137,13 @@ void main() m[1] = -1.5; assert(m[1] == -1.5); assert(m.size() == 7); -#ifndef MOMO_USE_SAFE_MAP_BRACKETS assert(m[6] == 0); assert(m.size() == 8); -#endif m[6] = 6.5; assert(m[6] == 6.5); assert(m.size() == 8); } #endif + + return 0; } diff --git a/test/sources/libcxx/map/map.access/index_rv_key.pass.cpp b/test/sources/libcxx/map/map.access/index_rv_key.pass.cpp index d58f1c4f8..5227a0eb4 100644 --- a/test/sources/libcxx/map/map.access/index_rv_key.pass.cpp +++ b/test/sources/libcxx/map/map.access/index_rv_key.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -11,24 +10,26 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03 + // // class map // mapped_type& operator[](key_type&& k); -//#include -//#include - -//#include "test_macros.h" -//#include "MoveOnly.h" -//#include "min_allocator.h" +namespace TCT { +template , class Value = CopyInsertable<2>, + class ValueTp = std::pair > +using map = + std::map, + ContainerTestAllocator >; +} -void main() +int main(int, char**) { -//#if TEST_STD_VER >= 11 { - map m; + std::map m; assert(m.size() == 0); #ifndef MOMO_USE_SAFE_MAP_BRACKETS assert(m[1] == 0.0); @@ -45,10 +46,9 @@ void main() assert(m[6] == 6.5); assert(m.size() == 2); } -#ifdef LIBCPP_TEST_MIN_ALLOCATOR { typedef std::pair V; - map, min_allocator> m; + std::map, min_allocator> m; assert(m.size() == 0); assert(m[1] == 0.0); assert(m.size() == 1); @@ -61,5 +61,30 @@ void main() assert(m[6] == 6.5); assert(m.size() == 2); } +#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO + { + // Use "container_test_types.h" to check what arguments get passed + // to the allocator for operator[] + using Container = TCT::map<>; + using Key = Container::key_type; + using MappedType = Container::mapped_type; + ConstructController* cc = getConstructController(); + cc->reset(); + { + Container c; + Key k(1); + cc->expect&&, std::tuple<>&&>(); + MappedType& mref = c[std::move(k)]; + assert(!cc->unchecked()); + { + Key k2(1); + DisableAllocationGuard g; + MappedType& mref2 = c[std::move(k2)]; + assert(&mref == &mref2); + } + } + } #endif + + return 0; } diff --git a/test/sources/libcxx/map/map.access/iterator.pass.cpp b/test/sources/libcxx/map/map.access/iterator.pass.cpp index b4fa007e2..eb9c4882a 100644 --- a/test/sources/libcxx/map/map.access/iterator.pass.cpp +++ b/test/sources/libcxx/map/map.access/iterator.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -30,12 +29,7 @@ // const_reverse_iterator crbegin() const; // const_reverse_iterator crend() const; -//#include -//#include - -//#include "min_allocator.h" - -void main() +int main(int, char**) { { typedef std::pair V; @@ -66,20 +60,30 @@ void main() V(8, 1.5), V(8, 2) }; - map m(ar, ar+sizeof(ar)/sizeof(ar[0])); - assert(momo::internal::UIntMath<>::Dist(m.begin(), m.end()) == m.size()); - assert(momo::internal::UIntMath<>::Dist(m.rbegin(), m.rend()) == m.size()); - map::iterator i; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(static_cast(std::distance(m.begin(), m.end())) == m.size()); + assert(static_cast(std::distance(m.rbegin(), m.rend())) == m.size()); + std::map::iterator i; i = m.begin(); - map::const_iterator k = i; + std::map::const_iterator k = i; assert(i == k); - for (size_t j = 1; j <= m.size(); ++j, ++i) + for (int j = 1; static_cast(j) <= m.size(); ++j, ++i) { - assert(i->first == static_cast(j)); + assert(i->first == j); assert(i->second == 1); i->second = 2.5; assert(i->second == 2.5); } + assert(i == m.end()); + for (int j = static_cast(m.size()); j >= 1; --j) + { + --i; + assert(i->first == j); + assert(i->second == 2.5); + i->second = 1; + assert(i->second == 1); + } + assert(i == m.begin()); } { typedef std::pair V; @@ -110,21 +114,28 @@ void main() V(8, 1.5), V(8, 2) }; - const map m(ar, ar+sizeof(ar)/sizeof(ar[0])); - assert(momo::internal::UIntMath<>::Dist(m.begin(), m.end()) == m.size()); - assert(momo::internal::UIntMath<>::Dist(m.cbegin(), m.cend()) == m.size()); - assert(momo::internal::UIntMath<>::Dist(m.rbegin(), m.rend()) == m.size()); - assert(momo::internal::UIntMath<>::Dist(m.crbegin(), m.crend()) == m.size()); - map::const_iterator i; + const std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(static_cast(std::distance(m.begin(), m.end())) == m.size()); + assert(static_cast(std::distance(m.cbegin(), m.cend())) == m.size()); + assert(static_cast(std::distance(m.rbegin(), m.rend())) == m.size()); + assert(static_cast(std::distance(m.crbegin(), m.crend())) == m.size()); + std::map::const_iterator i; i = m.begin(); - for (size_t j = 1; j <= m.size(); ++j, ++i) + for (int j = 1; static_cast(j) <= m.size(); ++j, ++i) { - assert(i->first == static_cast(j)); + assert(i->first == j); assert(i->second == 1); } + assert(i == m.end()); + for (int j = static_cast(m.size()); j >= 1; --j) + { + --i; + assert(i->first == j); + assert(i->second == 1); + } + assert(i == m.begin()); } -//#if __cplusplus >= 201103L -#ifdef LIBCPP_TEST_MIN_ALLOCATOR +#if TEST_STD_VER >= 11 { typedef std::pair V; V ar[] = @@ -154,20 +165,30 @@ void main() V(8, 1.5), V(8, 2) }; - map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); - assert(std::distance(m.begin(), m.end()) == m.size()); - assert(std::distance(m.rbegin(), m.rend()) == m.size()); - map, min_allocator>::iterator i; + std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(static_cast(std::distance(m.begin(), m.end())) == m.size()); + assert(static_cast(std::distance(m.rbegin(), m.rend())) == m.size()); + std::map, min_allocator>::iterator i; i = m.begin(); - map, min_allocator>::const_iterator k = i; + std::map, min_allocator>::const_iterator k = i; assert(i == k); - for (int j = 1; j <= m.size(); ++j, ++i) + for (int j = 1; static_cast(j) <= m.size(); ++j, ++i) { assert(i->first == j); assert(i->second == 1); i->second = 2.5; assert(i->second == 2.5); } + assert(i == m.end()); + for (int j = static_cast(m.size()); j >= 1; --j) + { + --i; + assert(i->first == j); + assert(i->second == 2.5); + i->second = 1; + assert(i->second == 1); + } + assert(i == m.begin()); } { typedef std::pair V; @@ -198,23 +219,31 @@ void main() V(8, 1.5), V(8, 2) }; - const map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); - assert(std::distance(m.begin(), m.end()) == m.size()); - assert(std::distance(m.cbegin(), m.cend()) == m.size()); - assert(std::distance(m.rbegin(), m.rend()) == m.size()); - assert(std::distance(m.crbegin(), m.crend()) == m.size()); - map, min_allocator>::const_iterator i; + const std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(static_cast(std::distance(m.begin(), m.end())) == m.size()); + assert(static_cast(std::distance(m.cbegin(), m.cend())) == m.size()); + assert(static_cast(std::distance(m.rbegin(), m.rend())) == m.size()); + assert(static_cast(std::distance(m.crbegin(), m.crend())) == m.size()); + std::map, min_allocator>::const_iterator i; i = m.begin(); - for (int j = 1; j <= m.size(); ++j, ++i) + for (int j = 1; static_cast(j) <= m.size(); ++j, ++i) { assert(i->first == j); assert(i->second == 1); } + assert(i == m.end()); + for (int j = static_cast(m.size()); j >= 1; --j) + { + --i; + assert(i->first == j); + assert(i->second == 1); + } + assert(i == m.begin()); } #endif -//#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { // N3644 testing - typedef map C; + typedef std::map C; C::iterator ii1{}, ii2{}; C::iterator ii4 = ii1; C::const_iterator cii{}; @@ -228,5 +257,7 @@ void main() assert (!(ii1 != cii )); assert (!(cii != ii1 )); } -//#endif +#endif + + return 0; } diff --git a/test/sources/libcxx/map/map.access/max_size.pass.cpp b/test/sources/libcxx/map/map.access/max_size.pass.cpp index 3839d4054..1deb187ff 100644 --- a/test/sources/libcxx/map/map.access/max_size.pass.cpp +++ b/test/sources/libcxx/map/map.access/max_size.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -17,24 +16,33 @@ // size_type max_size() const; -//#include -//#include - -//#include "min_allocator.h" - -void main() +int main(int, char**) { - { - typedef map M; - M m; - assert(m.max_size() != 0); - } -//#if __cplusplus >= 201103L -#ifdef LIBCPP_TEST_MIN_ALLOCATOR - { - typedef map, min_allocator>> M; - M m; - assert(m.max_size() != 0); - } -#endif + typedef std::pair KV; + { + typedef limited_allocator A; + typedef std::map, A> C; + C c; + assert(c.max_size() <= 10); + LIBCPP_ASSERT(c.max_size() == 10); + } + { + typedef limited_allocator A; + typedef std::map, A> C; + const C::size_type max_dist = + static_cast(std::numeric_limits::max()); + C c; + assert(c.max_size() <= max_dist); + LIBCPP_ASSERT(c.max_size() == max_dist); + } + { + typedef std::map C; + const C::size_type max_dist = + static_cast(std::numeric_limits::max()); + C c; + assert(c.max_size() <= max_dist); + assert(c.max_size() <= alloc_max_size(c.get_allocator())); + } + + return 0; } diff --git a/test/sources/libcxx/map/map.access/size.pass.cpp b/test/sources/libcxx/map/map.access/size.pass.cpp index dd5e889cb..39671bde3 100644 --- a/test/sources/libcxx/map/map.access/size.pass.cpp +++ b/test/sources/libcxx/map/map.access/size.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -17,15 +16,10 @@ // size_type size() const; -//#include -//#include - -//#include "min_allocator.h" - -void main() +int main(int, char**) { { - typedef map M; + typedef std::map M; M m; assert(m.size() == 0); m.insert(M::value_type(2, 1.5)); @@ -41,10 +35,9 @@ void main() m.erase(m.begin()); assert(m.size() == 0); } -//#if __cplusplus >= 201103L -#ifdef LIBCPP_TEST_MIN_ALLOCATOR +#if TEST_STD_VER >= 11 { - typedef map, min_allocator>> M; + typedef std::map, min_allocator>> M; M m; assert(m.size() == 0); m.insert(M::value_type(2, 1.5)); @@ -61,4 +54,6 @@ void main() assert(m.size() == 0); } #endif + + return 0; }