Skip to content

Commit

Permalink
Update libcxx/map
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Nov 26, 2023
1 parent 44d9888 commit 8cd5f70
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 149 deletions.
44 changes: 23 additions & 21 deletions test/sources/libcxx/map/map.access/at.pass.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// Modified for https://github.com/morzhovets/momo project.
//
//===----------------------------------------------------------------------===//

// XFAIL: libcpp-no-exceptions
// <map>

// class map

// mapped_type& at(const key_type& k);
// const mapped_type& at(const key_type& k) const;

//#include <map>
//#include <cassert>

//#include "min_allocator.h"

void main()
int main(int, char**)
{
{
typedef std::pair<const int, double> V;
Expand All @@ -38,7 +31,7 @@ void main()
V(7, 7.5),
V(8, 8.5),
};
map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 7);
assert(m.at(1) == 1.5);
m.at(1) = -1.5;
Expand All @@ -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);
Expand All @@ -71,27 +66,28 @@ void main()
V(7, 7.5),
V(8, 8.5),
};
const map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
const std::map<int, double> 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<const int, double> V;
V ar[] =
Expand All @@ -104,7 +100,7 @@ void main()
V(7, 7.5),
V(8, 8.5),
};
map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 7);
assert(m.at(1) == 1.5);
m.at(1) = -1.5;
Expand All @@ -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);
Expand All @@ -137,24 +135,28 @@ void main()
V(7, 7.5),
V(8, 8.5),
};
const map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
const std::map<int, double, std::less<int>, min_allocator<V>> 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;
}
23 changes: 9 additions & 14 deletions test/sources/libcxx/map/map.access/empty.pass.cpp
Original file line number Diff line number Diff line change
@@ -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
//
//===----------------------------------------------------------------------===//
//
Expand All @@ -17,26 +16,20 @@

// bool empty() const;

//#include <map>
//#include <cassert>

//#include "min_allocator.h"

void main()
int main(int, char**)
{
{
typedef map<int, double> M;
typedef std::map<int, double> M;
M m;
assert(m.empty());
m.insert(M::value_type(1, 1.5));
assert(!m.empty());
m.clear();
assert(m.empty());
}
//#if __cplusplus >= 201103L
#ifdef LIBCPP_TEST_MIN_ALLOCATOR
#if TEST_STD_VER >= 11
{
typedef map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
M m;
assert(m.empty());
m.insert(M::value_type(1, 1.5));
Expand All @@ -45,4 +38,6 @@ void main()
assert(m.empty());
}
#endif

return 0;
}
72 changes: 53 additions & 19 deletions test/sources/libcxx/map/map.access/index_key.pass.cpp
Original file line number Diff line number Diff line change
@@ -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
//
//===----------------------------------------------------------------------===//
//
Expand All @@ -17,13 +16,15 @@

// mapped_type& operator[](const key_type& k);

//#include <map>
//#include <cassert>

//#include "min_allocator.h"
//#include "private_constructor.hpp"
namespace TCT {
template <class Key = CopyInsertable<1>, class Value = CopyInsertable<2>,
class ValueTp = std::pair<const Key, Value> >
using map =
std::map<Key, Value, std::less<Key>,
ContainerTestAllocator<ValueTp, ValueTp> >;
}

void main()
int main(int, char**)
{
{
typedef std::pair<const int, double> V;
Expand All @@ -37,7 +38,7 @@ void main()
V(7, 7.5),
V(8, 8.5),
};
map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 7);
assert(m[1] == 1.5);
assert(m.size() == 7);
Expand All @@ -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<const int, double> V;
V ar[] =
Expand All @@ -66,7 +66,7 @@ void main()
V(7, 7.5),
V(8, 8.5),
};
map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 7);
assert(m[1] == 1.5);
assert(m.size() == 7);
Expand All @@ -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::piecewise_construct_t const&, std::tuple<Key const&>&&, 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::piecewise_construct_t const&, std::tuple<Key const&>&&, 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<const int, double> V;
V ar[] =
Expand All @@ -95,21 +129,21 @@ void main()
V(7, 7.5),
V(8, 8.5),
};
map<int, double, std::less<>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
std::map<int, double, std::less<>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));

assert(m.size() == 7);
assert(m[1] == 1.5);
assert(m.size() == 7);
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;
}
Loading

0 comments on commit 8cd5f70

Please sign in to comment.