[libcxx-commits] [libcxx] [libc++] Make map constexpr as part of P3372R3 (PR #134330)
Vinay Deshmukh via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Apr 6 11:25:14 PDT 2025
https://github.com/vinay-deshmukh updated https://github.com/llvm/llvm-project/pull/134330
>From 83583bb59845a52d7cbc6e1688ea6c809396c7e8 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Thu, 3 Apr 2025 20:35:56 -0400
Subject: [PATCH 01/11] Apply initial _LIBCPP_CONSTEXPR_SINCE_CXX26
---
libcxx/include/map | 238 ++++++++++++++++++++++++++++-----------------
1 file changed, 150 insertions(+), 88 deletions(-)
diff --git a/libcxx/include/map b/libcxx/include/map
index e7e0c14e36999..3719efd6b6e73 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -989,10 +989,11 @@ public:
protected:
key_compare comp;
- _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : comp(__c) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare(key_compare __c) : comp(__c) {}
public:
- _LIBCPP_HIDE_FROM_ABI bool operator()(const value_type& __x, const value_type& __y) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool
+ operator()(const value_type& __x, const value_type& __y) const {
return comp(__x.first, __y.first);
}
};
@@ -1029,26 +1030,27 @@ public:
template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS multimap;
- _LIBCPP_HIDE_FROM_ABI map() _NOEXCEPT_(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map() _NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__vc(key_compare())) {}
- _LIBCPP_HIDE_FROM_ABI explicit map(const key_compare& __comp) _NOEXCEPT_(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit map(const key_compare& __comp) _NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__vc(__comp)) {}
- _LIBCPP_HIDE_FROM_ABI explicit map(const key_compare& __comp, const allocator_type& __a)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit map(const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI map(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare())
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ map(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare())
: __tree_(__vc(__comp)) {
insert(__f, __l);
}
template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
map(_InputIterator __f, _InputIterator __l, const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
insert(__f, __l);
@@ -1056,7 +1058,7 @@ public:
# if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<value_type> _Range>
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
map(from_range_t,
_Range&& __range,
const key_compare& __comp = key_compare(),
@@ -1068,19 +1070,22 @@ public:
# if _LIBCPP_STD_VER >= 14
template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
: map(__f, __l, key_compare(), __a) {}
# endif
# if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<value_type> _Range>
- _LIBCPP_HIDE_FROM_ABI map(from_range_t, _Range&& __range, const allocator_type& __a)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map(from_range_t, _Range&& __range, const allocator_type& __a)
: map(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
# endif
- _LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map(const map& __m) : __tree_(__m.__tree_) {
+ insert(__m.begin(), __m.end());
+ }
- _LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map& operator=(const map& __m) {
# ifndef _LIBCPP_CXX03_LANG
__tree_ = __m.__tree_;
# else
@@ -1096,32 +1101,36 @@ public:
# ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
: __tree_(std::move(__m.__tree_)) {}
- _LIBCPP_HIDE_FROM_ABI map(map&& __m, const allocator_type& __a);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map(map&& __m, const allocator_type& __a);
- _LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map&
+ operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
__tree_ = std::move(__m.__tree_);
return *this;
}
- _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
: __tree_(__vc(__comp)) {
insert(__il.begin(), __il.end());
}
- _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
insert(__il.begin(), __il.end());
}
# if _LIBCPP_STD_VER >= 14
- _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const allocator_type& __a)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map(initializer_list<value_type> __il, const allocator_type& __a)
: map(__il, key_compare(), __a) {}
# endif
- _LIBCPP_HIDE_FROM_ABI map& operator=(initializer_list<value_type> __il) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map& operator=(initializer_list<value_type> __il) {
__tree_.__assign_unique(__il.begin(), __il.end());
return *this;
}
@@ -1130,43 +1139,65 @@ public:
_LIBCPP_HIDE_FROM_ABI explicit map(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) {}
- _LIBCPP_HIDE_FROM_ABI map(const map& __m, const allocator_type& __a)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 map(const map& __m, const allocator_type& __a)
: __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) {
insert(__m.begin(), __m.end());
}
- _LIBCPP_HIDE_FROM_ABI ~map() { static_assert(sizeof(std::__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 ~map() {
+ static_assert(sizeof(std::__diagnose_non_const_comparator<_Key, _Compare>()), "");
+ }
- _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
- _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
- _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
- _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator begin() _NOEXCEPT { return __tree_.begin(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator end() _NOEXCEPT { return __tree_.end(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator end() const _NOEXCEPT { return __tree_.end(); }
- _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
- _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rbegin() _NOEXCEPT {
+ return reverse_iterator(end());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rbegin() const _NOEXCEPT {
+ return const_reverse_iterator(end());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rend() _NOEXCEPT {
+ return reverse_iterator(begin());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rend() const _NOEXCEPT {
+ return const_reverse_iterator(begin());
+ }
- _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
- _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cbegin() const _NOEXCEPT { return begin(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cend() const _NOEXCEPT { return end(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crbegin() const _NOEXCEPT {
+ return rbegin();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
- [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
- _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
- _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool empty() const _NOEXCEPT {
+ return __tree_.size() == 0;
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type size() const _NOEXCEPT { return __tree_.size(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type max_size() const _NOEXCEPT {
+ return __tree_.max_size();
+ }
- _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](const key_type& __k);
# ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](key_type&& __k);
# endif
- _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k);
- _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& at(const key_type& __k);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const mapped_type& at(const key_type& __k) const;
- _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(__tree_.__alloc()); }
- _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp().key_comp(); }
- _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__tree_.value_comp().key_comp()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 allocator_type get_allocator() const _NOEXCEPT {
+ return allocator_type(__tree_.__alloc());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 key_compare key_comp() const {
+ return __tree_.value_comp().key_comp();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare value_comp() const {
+ return value_compare(__tree_.value_comp().key_comp());
+ }
# ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
@@ -1853,50 +1884,56 @@ public:
# ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator emplace(_Args&&... __args) {
return __tree_.__emplace_multi(std::forward<_Args>(__args)...);
}
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
return __tree_.__emplace_hint_multi(__p.__i_, std::forward<_Args>(__args)...);
}
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI iterator insert(_Pp&& __p) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(_Pp&& __p) {
return __tree_.__insert_multi(std::forward<_Pp>(__p));
}
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __pos, _Pp&& __p) {
return __tree_.__insert_multi(__pos.__i_, std::forward<_Pp>(__p));
}
- _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(value_type&& __v) {
+ return __tree_.__insert_multi(std::move(__v));
+ }
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __p, value_type&& __v) {
return __tree_.__insert_multi(__p.__i_, std::move(__v));
}
- _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(initializer_list<value_type> __il) {
+ insert(__il.begin(), __il.end());
+ }
# endif // _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const value_type& __v) {
+ return __tree_.__insert_multi(__v);
+ }
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __p, const value_type& __v) {
return __tree_.__insert_multi(__p.__i_, __v);
}
template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(_InputIterator __f, _InputIterator __l) {
for (const_iterator __e = cend(); __f != __l; ++__f)
__tree_.__insert_multi(__e.__i_, *__f);
}
# if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<value_type> _Range>
- _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert_range(_Range&& __range) {
const_iterator __end = cend();
for (auto&& __element : __range) {
__tree_.__insert_multi(__end.__i_, std::forward<decltype(__element)>(__element));
@@ -1904,131 +1941,156 @@ public:
}
# endif
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
- _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
- _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_multi(__k); }
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __p) {
+ return __tree_.erase(__p.__i_);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(const key_type& __k) {
+ return __tree_.__erase_multi(__k);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __f, const_iterator __l) {
return __tree_.erase(__f.__i_, __l.__i_);
}
# if _LIBCPP_STD_VER >= 17
- _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(node_type&& __nh) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to multimap::insert()");
return __tree_.template __node_handle_insert_multi<node_type>(std::move(__nh));
}
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, node_type&& __nh) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to multimap::insert()");
return __tree_.template __node_handle_insert_multi<node_type>(__hint.__i_, std::move(__nh));
}
- _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 node_type extract(key_type const& __key) {
return __tree_.template __node_handle_extract<node_type>(__key);
}
- _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 node_type extract(const_iterator __it) {
return __tree_.template __node_handle_extract<node_type>(__it.__i_);
}
template <class _Compare2>
- _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
+ merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
__source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
- _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
+ merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
__source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
- _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
+ merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
__source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
- _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
+ merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
__source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
# endif
- _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void clear() _NOEXCEPT { __tree_.clear(); }
- _LIBCPP_HIDE_FROM_ABI void swap(multimap& __m) _NOEXCEPT_(__is_nothrow_swappable_v<__base>) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(multimap& __m)
+ _NOEXCEPT_(__is_nothrow_swappable_v<__base>) {
__tree_.swap(__m.__tree_);
}
- _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
- _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const key_type& __k) { return __tree_.find(__k); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const key_type& __k) const {
+ return __tree_.find(__k);
+ }
# if _LIBCPP_STD_VER >= 14
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const _K2& __k) {
return __tree_.find(__k);
}
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const _K2& __k) const {
return __tree_.find(__k);
}
# endif
- _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_multi(__k); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const key_type& __k) const {
+ return __tree_.__count_multi(__k);
+ }
# if _LIBCPP_STD_VER >= 14
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const _K2& __k) const {
return __tree_.__count_multi(__k);
}
# endif
# if _LIBCPP_STD_VER >= 20
- _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const key_type& __k) const {
+ return find(__k) != end();
+ }
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const _K2& __k) const {
return find(__k) != end();
}
# endif // _LIBCPP_STD_VER >= 20
- _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
- _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const key_type& __k) {
+ return __tree_.lower_bound(__k);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const key_type& __k) const {
+ return __tree_.lower_bound(__k);
+ }
# if _LIBCPP_STD_VER >= 14
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const _K2& __k) {
return __tree_.lower_bound(__k);
}
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const _K2& __k) const {
return __tree_.lower_bound(__k);
}
# endif
- _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
- _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const key_type& __k) {
+ return __tree_.upper_bound(__k);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const key_type& __k) const {
+ return __tree_.upper_bound(__k);
+ }
# if _LIBCPP_STD_VER >= 14
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const _K2& __k) {
return __tree_.upper_bound(__k);
}
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const _K2& __k) const {
return __tree_.upper_bound(__k);
}
# endif
- _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const key_type& __k) {
return __tree_.__equal_range_multi(__k);
}
- _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
+ equal_range(const key_type& __k) const {
return __tree_.__equal_range_multi(__k);
}
# if _LIBCPP_STD_VER >= 14
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const _K2& __k) {
return __tree_.__equal_range_multi(__k);
}
template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
+ equal_range(const _K2& __k) const {
return __tree_.__equal_range_multi(__k);
}
# endif
>From 6560dd52ad94443674334585ef8d01f59032f59c Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Thu, 3 Apr 2025 20:37:35 -0400
Subject: [PATCH 02/11] Add feature test macro
---
libcxx/docs/FeatureTestMacroTable.rst | 2 ++
libcxx/include/version | 2 ++
2 files changed, 4 insertions(+)
diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index bbcc76b52f0a9..a72ddbdb3e67a 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -210,6 +210,8 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_constexpr_iterator`` ``201811L``
---------------------------------------------------------- -----------------
+ ``__cpp_lib_constexpr_map`` ``202502L``
+ ---------------------------------------------------------- -----------------
``__cpp_lib_constexpr_memory`` ``201811L``
---------------------------------------------------------- -----------------
``__cpp_lib_constexpr_numeric`` ``201911L``
diff --git a/libcxx/include/version b/libcxx/include/version
index 83ae11dabd2bc..4f94be1ca14a8 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -69,6 +69,7 @@ __cpp_lib_constexpr_complex 201711L <complex>
__cpp_lib_constexpr_dynamic_alloc 201907L <memory>
__cpp_lib_constexpr_functional 201907L <functional>
__cpp_lib_constexpr_iterator 201811L <iterator>
+__cpp_lib_constexpr_map 202502L <map>
__cpp_lib_constexpr_memory 202202L <memory>
201811L // C++20
__cpp_lib_constexpr_new 202406L <new>
@@ -538,6 +539,7 @@ __cpp_lib_void_t 201411L <type_traits>
# define __cpp_lib_bind_front 202306L
# define __cpp_lib_bitset 202306L
# undef __cpp_lib_constexpr_algorithms
+# define __cpp_lib_constexpr_map 202502L
# define __cpp_lib_constexpr_algorithms 202306L
# if !defined(_LIBCPP_ABI_VCRUNTIME)
# define __cpp_lib_constexpr_new 202406L
>From ce1a62f120212634daab4d844aec1e2ac343e4df Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Thu, 3 Apr 2025 21:20:23 -0400
Subject: [PATCH 03/11] one test to start with
---
.../associative/map/map.cons/alloc.pass.cpp | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp
index 52199204d7914..9b854659c38f9 100644
--- a/libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// explicit map(const allocator_type& a);
+// explicit map(const allocator_type& a); // constexpr since C++26
#include <map>
#include <cassert>
@@ -19,7 +19,7 @@
#include "test_allocator.h"
#include "min_allocator.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::less<int> C;
typedef test_allocator<std::pair<const int, double> > A;
@@ -46,6 +46,13 @@ int main(int, char**) {
assert(m.get_allocator() == A());
}
#endif
+ return true;
+}
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
>From a72b619c130bfd03f50f662556989cc217c73032 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sat, 5 Apr 2025 02:00:35 -0400
Subject: [PATCH 04/11] start seeing constexpr failures for at.pass.cpp
---
libcxx/include/__tree | 62 +++++++++---------
libcxx/include/map | 64 +++++++++----------
.../associative/map/map.access/at.pass.cpp | 13 +++-
3 files changed, 73 insertions(+), 66 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 9d28381c8c2ce..ff57d63f15789 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -967,39 +967,39 @@ public:
typedef __tree_iterator<value_type, __node_pointer, difference_type> iterator;
typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator;
- _LIBCPP_HIDE_FROM_ABI explicit __tree(const value_compare& __comp) _NOEXCEPT_(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree(const value_compare& __comp) _NOEXCEPT_(
is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value);
- _LIBCPP_HIDE_FROM_ABI explicit __tree(const allocator_type& __a);
- _LIBCPP_HIDE_FROM_ABI __tree(const value_compare& __comp, const allocator_type& __a);
- _LIBCPP_HIDE_FROM_ABI __tree(const __tree& __t);
- _LIBCPP_HIDE_FROM_ABI __tree& operator=(const __tree& __t);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree(const allocator_type& __a);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(const value_compare& __comp, const allocator_type& __a);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(const __tree& __t);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree& operator=(const __tree& __t);
template <class _ForwardIterator>
- _LIBCPP_HIDE_FROM_ABI void __assign_unique(_ForwardIterator __first, _ForwardIterator __last);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __assign_unique(_ForwardIterator __first, _ForwardIterator __last);
template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI void __assign_multi(_InputIterator __first, _InputIterator __last);
- _LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t) _NOEXCEPT_(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __assign_multi(_InputIterator __first, _InputIterator __last);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(__tree&& __t) _NOEXCEPT_(
is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible<value_compare>::value);
- _LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t, const allocator_type& __a);
- _LIBCPP_HIDE_FROM_ABI __tree& operator=(__tree&& __t)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree(__tree&& __t, const allocator_type& __a);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree& operator=(__tree&& __t)
_NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
((__node_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<__node_allocator>::value) ||
allocator_traits<__node_allocator>::is_always_equal::value));
- _LIBCPP_HIDE_FROM_ABI ~__tree();
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 ~__tree();
- _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__begin_node()); }
- _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__begin_node()); }
- _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(__end_node()); }
- _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(__end_node()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator begin() _NOEXCEPT { return iterator(__begin_node()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator begin() const _NOEXCEPT { return const_iterator(__begin_node()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator end() _NOEXCEPT { return iterator(__end_node()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator end() const _NOEXCEPT { return const_iterator(__end_node()); }
- _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type max_size() const _NOEXCEPT {
return std::min<size_type>(__node_traits::max_size(__node_alloc()), numeric_limits<difference_type >::max());
}
- _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void clear() _NOEXCEPT;
- _LIBCPP_HIDE_FROM_ABI void swap(__tree& __t)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(__tree& __t)
#if _LIBCPP_STD_VER <= 11
_NOEXCEPT_(__is_nothrow_swappable_v<value_compare> &&
(!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>));
@@ -1315,20 +1315,20 @@ private:
};
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_(
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_(
is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value)
: __size_(0), __value_comp_(__comp) {
__begin_node() = __end_node();
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
: __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0) {
__begin_node() = __end_node();
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a)
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a)
: __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) {
__begin_node() = __end_node();
}
@@ -1375,7 +1375,7 @@ __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_poin
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) {
if (this != std::addressof(__t)) {
value_comp() = __t.value_comp();
__copy_assign_alloc(__t);
@@ -1386,7 +1386,7 @@ __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(
template <class _Tp, class _Compare, class _Allocator>
template <class _ForwardIterator>
-void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first, _ForwardIterator __last) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first, _ForwardIterator __last) {
typedef iterator_traits<_ForwardIterator> _ITraits;
typedef typename _ITraits::value_type _ItValueType;
static_assert(is_same<_ItValueType, __container_value_type>::value,
@@ -1406,7 +1406,7 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first
template <class _Tp, class _Compare, class _Allocator>
template <class _InputIterator>
-void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) {
typedef iterator_traits<_InputIterator> _ITraits;
typedef typename _ITraits::value_type _ItValueType;
static_assert(
@@ -1426,7 +1426,7 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
: __begin_node_(__iter_pointer()),
__node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())),
__size_(0),
@@ -1435,7 +1435,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible<value_compare>::value)
: __begin_node_(std::move(__t.__begin_node_)),
__end_node_(std::move(__t.__end_node_)),
@@ -1453,7 +1453,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a)
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a)
: __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(std::move(__t.value_comp())) {
if (__a == __t.__alloc()) {
if (__t.size() == 0)
@@ -1512,7 +1512,7 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) {
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t)
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t)
_NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
((__node_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<__node_allocator>::value) ||
@@ -1522,7 +1522,7 @@ __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(
}
template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::~__tree() {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::~__tree() {
static_assert(is_copy_constructible<value_compare>::value, "Comparator must be copy-constructible.");
destroy(__root());
}
@@ -1539,7 +1539,7 @@ void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT {
}
template <class _Tp, class _Compare, class _Allocator>
-void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
+_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
#if _LIBCPP_STD_VER <= 11
_NOEXCEPT_(__is_nothrow_swappable_v<value_compare> &&
(!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>))
@@ -1564,7 +1564,7 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
}
template <class _Tp, class _Compare, class _Allocator>
-void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT {
destroy(__root());
size() = 0;
__begin_node() = __end_node();
diff --git a/libcxx/include/map b/libcxx/include/map
index 3719efd6b6e73..3ae485f1ce029 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -1201,54 +1201,54 @@ public:
# ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> emplace(_Args&&... __args) {
return __tree_.__emplace_unique(std::forward<_Args>(__args)...);
}
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
return __tree_.__emplace_hint_unique(__p.__i_, std::forward<_Args>(__args)...);
}
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __p) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(_Pp&& __p) {
return __tree_.__insert_unique(std::forward<_Pp>(__p));
}
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __pos, _Pp&& __p) {
return __tree_.__insert_unique(__pos.__i_, std::forward<_Pp>(__p));
}
# endif // _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __p, const value_type& __v) {
return __tree_.__insert_unique(__p.__i_, __v);
}
# ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(value_type&& __v) {
return __tree_.__insert_unique(std::move(__v));
}
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __p, value_type&& __v) {
return __tree_.__insert_unique(__p.__i_, std::move(__v));
}
- _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
# endif
template <class _InputIterator>
- _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(_InputIterator __f, _InputIterator __l) {
for (const_iterator __e = cend(); __f != __l; ++__f)
insert(__e.__i_, *__f);
}
# if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<value_type> _Range>
- _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert_range(_Range&& __range) {
const_iterator __end = cend();
for (auto&& __element : __range) {
insert(__end.__i_, std::forward<decltype(__element)>(__element));
@@ -1259,7 +1259,7 @@ public:
# if _LIBCPP_STD_VER >= 17
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) {
return __tree_.__emplace_unique_key_args(
__k,
std::piecewise_construct,
@@ -1268,7 +1268,7 @@ public:
}
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) {
return __tree_.__emplace_unique_key_args(
__k,
std::piecewise_construct,
@@ -1277,7 +1277,7 @@ public:
}
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) {
return __tree_
.__emplace_hint_unique_key_args(
__h.__i_,
@@ -1289,7 +1289,7 @@ public:
}
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) {
return __tree_
.__emplace_hint_unique_key_args(
__h.__i_,
@@ -1301,7 +1301,7 @@ public:
}
template <class _Vp>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) {
iterator __p = lower_bound(__k);
if (__p != end() && !key_comp()(__k, __p->first)) {
__p->second = std::forward<_Vp>(__v);
@@ -1311,7 +1311,7 @@ public:
}
template <class _Vp>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) {
iterator __p = lower_bound(__k);
if (__p != end() && !key_comp()(__k, __p->first)) {
__p->second = std::forward<_Vp>(__v);
@@ -1321,7 +1321,7 @@ public:
}
template <class _Vp>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) {
auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, __k, std::forward<_Vp>(__v));
if (!__inserted)
@@ -1331,7 +1331,7 @@ public:
}
template <class _Vp>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) {
auto [__r, __inserted] =
__tree_.__emplace_hint_unique_key_args(__h.__i_, __k, std::move(__k), std::forward<_Vp>(__v));
@@ -1343,26 +1343,26 @@ public:
# endif // _LIBCPP_STD_VER >= 17
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
- _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
- _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_unique(__k); }
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(const key_type& __k) { return __tree_.__erase_unique(__k); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __f, const_iterator __l) {
return __tree_.erase(__f.__i_, __l.__i_);
}
- _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void clear() _NOEXCEPT { __tree_.clear(); }
# if _LIBCPP_STD_VER >= 17
- _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 insert_return_type insert(node_type&& __nh) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to map::insert()");
return __tree_.template __node_handle_insert_unique< node_type, insert_return_type>(std::move(__nh));
}
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, node_type&& __nh) {
_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to map::insert()");
return __tree_.template __node_handle_insert_unique<node_type>(__hint.__i_, std::move(__nh));
}
- _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 node_type extract(key_type const& __key) {
return __tree_.template __node_handle_extract<node_type>(__key);
}
_LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
@@ -1537,7 +1537,7 @@ map(initializer_list<pair<_Key, _Tp>>,
# ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Compare, class _Allocator>
-map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
+_LIBCPP_CONSTEXPR_SINCE_CXX26 map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
: __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
if (__a != __m.get_allocator()) {
const_iterator __e = cend();
@@ -1547,7 +1547,7 @@ map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
-_Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
return __tree_
.__emplace_unique_key_args(__k, std::piecewise_construct, std::forward_as_tuple(__k), std::forward_as_tuple())
.first->__get_value()
@@ -1555,7 +1555,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
-_Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) {
// TODO investigate this clang-tidy warning.
// NOLINTBEGIN(bugprone-use-after-move)
return __tree_
@@ -1596,7 +1596,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
# endif // _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Compare, class _Allocator>
-_Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) {
__parent_pointer __parent;
__node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
if (__child == nullptr)
@@ -1605,7 +1605,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) {
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
-const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const {
__parent_pointer __parent;
__node_base_pointer __child = __tree_.__find_equal(__parent, __k);
if (__child == nullptr)
diff --git a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
index cabc9f7eb1066..26a0ad1ff1613 100644
--- a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
@@ -10,8 +10,8 @@
// class map
-// mapped_type& at(const key_type& k);
-// const mapped_type& at(const key_type& k) const;
+// mapped_type& at(const key_type& k); // constexpr since C++26
+// const mapped_type& at(const key_type& k) const; // constexpr since C++26
#include <cassert>
#include <map>
@@ -20,7 +20,7 @@
#include "min_allocator.h"
#include "test_macros.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::pair<const int, double> V;
V ar[] = {
@@ -143,6 +143,13 @@ int main(int, char**) {
assert(m.size() == 7);
}
#endif
+ return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
>From c04441ebd9f2a7b685f2bead883c6efcfc8b2cba Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sat, 5 Apr 2025 02:25:01 -0400
Subject: [PATCH 05/11] member call on object outside its lifetime is not
allowed in a constant expression
---
libcxx/include/__tree | 139 +++++++++---------
libcxx/include/map | 56 +++----
.../associative/map/map.access/empty.pass.cpp | 11 +-
.../map/map.access/empty.verify.cpp | 12 +-
.../map/map.access/index_key.pass.cpp | 11 +-
.../map/map.access/index_rv_key.pass.cpp | 11 +-
.../map/map.access/index_tuple.pass.cpp | 11 +-
.../map/map.access/iterator.pass.cpp | 33 +++--
.../map/map.access/max_size.pass.cpp | 11 +-
.../associative/map/map.access/size.pass.cpp | 11 +-
.../map.cons/assign_initializer_list.pass.cpp | 17 ++-
.../associative/map/map.cons/compare.pass.cpp | 11 +-
.../map/map.cons/compare_alloc.pass.cpp | 11 +-
.../map/map.cons/copy_alloc.pass.cpp | 11 +-
14 files changed, 223 insertions(+), 133 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index ff57d63f15789..c966236e51842 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -509,10 +509,10 @@ struct __tree_key_value_types {
typedef _Tp __container_value_type;
static const bool __is_map = false;
- _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(_Tp const& __v) { return __v; }
- _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; }
- _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) { return std::addressof(__n); }
- _LIBCPP_HIDE_FROM_ABI static __container_value_type&& __move(__node_value_type& __v) { return std::move(__v); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static key_type const& __get_key(_Tp const& __v) { return __v; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static __container_value_type* __get_ptr(__node_value_type& __n) { return std::addressof(__n); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static __container_value_type&& __move(__node_value_type& __v) { return std::move(__v); }
};
template <class _Key, class _Tp>
@@ -524,25 +524,25 @@ struct __tree_key_value_types<__value_type<_Key, _Tp> > {
typedef __container_value_type __map_value_type;
static const bool __is_map = true;
- _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(__node_value_type const& __t) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static key_type const& __get_key(__node_value_type const& __t) {
return __t.__get_value().first;
}
template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(_Up& __t) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static key_type const& __get_key(_Up& __t) {
return __t.first;
}
- _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(__node_value_type const& __t) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static __container_value_type const& __get_value(__node_value_type const& __t) {
return __t.__get_value();
}
template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static __container_value_type const& __get_value(_Up& __t) {
return __t;
}
- _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static __container_value_type* __get_ptr(__node_value_type& __n) {
return std::addressof(__n.__get_value());
}
@@ -626,7 +626,7 @@ public:
typedef _Pointer pointer;
pointer __left_;
- _LIBCPP_HIDE_FROM_ABI __tree_end_node() _NOEXCEPT : __left_() {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_end_node() _NOEXCEPT : __left_() {}
};
template <class _VoidPtr>
@@ -679,14 +679,14 @@ private:
public:
bool __value_constructed;
- _LIBCPP_HIDE_FROM_ABI __tree_node_destructor(const __tree_node_destructor&) = default;
- __tree_node_destructor& operator=(const __tree_node_destructor&) = delete;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_node_destructor(const __tree_node_destructor&) = default;
+ _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_node_destructor& operator=(const __tree_node_destructor&) = delete;
- _LIBCPP_HIDE_FROM_ABI explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT
: __na_(__na),
__value_constructed(__val) {}
- _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void operator()(pointer __p) _NOEXCEPT {
if (__value_constructed)
__alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
if (__p)
@@ -724,49 +724,49 @@ public:
typedef value_type& reference;
typedef typename _NodeTypes::__node_value_type_pointer pointer;
- _LIBCPP_HIDE_FROM_ABI __tree_iterator() _NOEXCEPT
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator() _NOEXCEPT
#if _LIBCPP_STD_VER >= 14
: __ptr_(nullptr)
#endif
{
}
- _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_np()->__value_; }
- _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__get_np()->__value_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __get_np()->__value_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits<pointer>::pointer_to(__get_np()->__value_); }
- _LIBCPP_HIDE_FROM_ABI __tree_iterator& operator++() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator& operator++() {
__ptr_ = static_cast<__iter_pointer>(
std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_)));
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __tree_iterator operator++(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator operator++(int) {
__tree_iterator __t(*this);
++(*this);
return __t;
}
- _LIBCPP_HIDE_FROM_ABI __tree_iterator& operator--() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator& operator--() {
__ptr_ = static_cast<__iter_pointer>(
std::__tree_prev_iter<__node_base_pointer>(static_cast<__end_node_pointer>(__ptr_)));
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __tree_iterator operator--(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_iterator operator--(int) {
__tree_iterator __t(*this);
--(*this);
return __t;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) {
return __x.__ptr_ == __y.__ptr_;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) {
return !(__x == __y);
}
private:
- _LIBCPP_HIDE_FROM_ABI explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
- _LIBCPP_HIDE_FROM_ABI explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
- _LIBCPP_HIDE_FROM_ABI __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); }
template <class, class, class>
friend class __tree;
template <class, class, class>
@@ -801,7 +801,7 @@ public:
typedef const value_type& reference;
typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
- _LIBCPP_HIDE_FROM_ABI __tree_const_iterator() _NOEXCEPT
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator() _NOEXCEPT
#if _LIBCPP_STD_VER >= 14
: __ptr_(nullptr)
#endif
@@ -812,46 +812,46 @@ private:
typedef __tree_iterator<value_type, __node_pointer, difference_type> __non_const_iterator;
public:
- _LIBCPP_HIDE_FROM_ABI __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
- _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_np()->__value_; }
- _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__get_np()->__value_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __get_np()->__value_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits<pointer>::pointer_to(__get_np()->__value_); }
- _LIBCPP_HIDE_FROM_ABI __tree_const_iterator& operator++() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator& operator++() {
__ptr_ = static_cast<__iter_pointer>(
std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_)));
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __tree_const_iterator operator++(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator operator++(int) {
__tree_const_iterator __t(*this);
++(*this);
return __t;
}
- _LIBCPP_HIDE_FROM_ABI __tree_const_iterator& operator--() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator& operator--() {
__ptr_ = static_cast<__iter_pointer>(
std::__tree_prev_iter<__node_base_pointer>(static_cast<__end_node_pointer>(__ptr_)));
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __tree_const_iterator operator--(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_const_iterator operator--(int) {
__tree_const_iterator __t(*this);
--(*this);
return __t;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {
return __x.__ptr_ == __y.__ptr_;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {
return !(__x == __y);
}
private:
- _LIBCPP_HIDE_FROM_ABI explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
- _LIBCPP_HIDE_FROM_ABI explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
- _LIBCPP_HIDE_FROM_ABI __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); }
template <class, class, class>
friend class __tree;
@@ -930,19 +930,19 @@ private:
_LIBCPP_COMPRESSED_PAIR(size_type, __size_, value_compare, __value_comp_);
public:
- _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __iter_pointer __end_node() _NOEXCEPT {
return static_cast<__iter_pointer>(pointer_traits<__end_node_ptr>::pointer_to(__end_node_));
}
- _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() const _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __iter_pointer __end_node() const _NOEXCEPT {
return static_cast<__iter_pointer>(
pointer_traits<__end_node_ptr>::pointer_to(const_cast<__end_node_t&>(__end_node_)));
}
- _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; }
private:
- _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; }
- _LIBCPP_HIDE_FROM_ABI __iter_pointer& __begin_node() _NOEXCEPT { return __begin_node_; }
- _LIBCPP_HIDE_FROM_ABI const __iter_pointer& __begin_node() const _NOEXCEPT { return __begin_node_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __iter_pointer& __begin_node() _NOEXCEPT { return __begin_node_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const __iter_pointer& __begin_node() const _NOEXCEPT { return __begin_node_; }
public:
_LIBCPP_HIDE_FROM_ABI allocator_type __alloc() const _NOEXCEPT { return allocator_type(__node_alloc()); }
@@ -1008,24 +1008,24 @@ public:
#endif
template <class _Key, class... _Args>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args&&... __args);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args&&... __args);
template <class _Key, class... _Args>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&&...);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&&...);
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_unique_impl(const_iterator __p, _Args&&... __args);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __emplace_hint_unique_impl(const_iterator __p, _Args&&... __args);
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator __emplace_multi(_Args&&... __args);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __emplace_multi(_Args&&... __args);
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
template <class _Pp>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique(_Pp&& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __emplace_unique(_Pp&& __x) {
return __emplace_unique_extract_key(std::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>());
}
@@ -1091,29 +1091,29 @@ public:
return __emplace_hint_unique_key_args(__p, __x.first, std::forward<_Pp>(__x)).first;
}
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(const __container_value_type& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __insert_unique(const __container_value_type& __v) {
return __emplace_unique_key_args(_NodeTypes::__get_key(__v), __v);
}
- _LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, const __container_value_type& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __insert_unique(const_iterator __p, const __container_value_type& __v) {
return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), __v).first;
}
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(__container_value_type&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __insert_unique(__container_value_type&& __v) {
return __emplace_unique_key_args(_NodeTypes::__get_key(__v), std::move(__v));
}
- _LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, __container_value_type&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __insert_unique(const_iterator __p, __container_value_type&& __v) {
return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), std::move(__v)).first;
}
template <class _Vp, __enable_if_t<!is_same<__remove_const_ref_t<_Vp>, __container_value_type>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(_Vp&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __insert_unique(_Vp&& __v) {
return __emplace_unique(std::forward<_Vp>(__v));
}
template <class _Vp, __enable_if_t<!is_same<__remove_const_ref_t<_Vp>, __container_value_type>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, _Vp&& __v) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __insert_unique(const_iterator __p, _Vp&& __v) {
return __emplace_hint_unique(__p, std::forward<_Vp>(__v));
}
@@ -1228,13 +1228,13 @@ public:
// FIXME: Make this function const qualified. Unfortunately doing so
// breaks existing code which uses non-const callable comparators.
template <class _Key>
- _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v);
template <class _Key>
- _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v) const {
return const_cast<__tree*>(this)->__find_equal(__parent, __v);
}
template <class _Key>
- _LIBCPP_HIDE_FROM_ABI __node_base_pointer&
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer&
__find_equal(const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v);
_LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __tree& __t) {
@@ -1255,7 +1255,7 @@ private:
__find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v);
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node(_Args&&... __args);
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_holder __construct_node(_Args&&... __args);
// TODO: Make this _LIBCPP_HIDE_FROM_ABI
_LIBCPP_HIDDEN void destroy(__node_pointer __nd) _NOEXCEPT;
@@ -1667,6 +1667,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, __parent_p
// If __v exists, set parent to node of __v and return reference to node of __v
template <class _Tp, class _Compare, class _Allocator>
template <class _Key>
+_LIBCPP_CONSTEXPR_SINCE_CXX26
typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&
__tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, const _Key& __v) {
__node_pointer __nd = __root();
@@ -1708,6 +1709,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, cons
// If __v exists, set parent to node of __v and return reference to node of __v
template <class _Tp, class _Compare, class _Allocator>
template <class _Key>
+_LIBCPP_CONSTEXPR_SINCE_CXX26
typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_equal(
const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v) {
if (__hint == end() || value_comp()(__v, *__hint)) // check before
@@ -1766,7 +1768,7 @@ void __tree<_Tp, _Compare, _Allocator>::__insert_node_at(
template <class _Tp, class _Compare, class _Allocator>
template <class _Key, class... _Args>
pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
-__tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) {
__parent_pointer __parent;
__node_base_pointer& __child = __find_equal(__parent, __k);
__node_pointer __r = static_cast<__node_pointer>(__child);
@@ -1783,7 +1785,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _A
template <class _Tp, class _Compare, class _Allocator>
template <class _Key, class... _Args>
pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
-__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
const_iterator __p, _Key const& __k, _Args&&... __args) {
__parent_pointer __parent;
__node_base_pointer __dummy;
@@ -1801,6 +1803,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
template <class _Tp, class _Compare, class _Allocator>
template <class... _Args>
+_LIBCPP_CONSTEXPR_SINCE_CXX26
typename __tree<_Tp, _Compare, _Allocator>::__node_holder
__tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) {
static_assert(!__is_tree_value_type<_Args...>::value, "Cannot construct from __value_type");
@@ -1814,7 +1817,7 @@ __tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) {
template <class _Tp, class _Compare, class _Allocator>
template <class... _Args>
pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
-__tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) {
__node_holder __h = __construct_node(std::forward<_Args>(__args)...);
__parent_pointer __parent;
__node_base_pointer& __child = __find_equal(__parent, __h->__value_);
@@ -1831,7 +1834,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) {
template <class _Tp, class _Compare, class _Allocator>
template <class... _Args>
typename __tree<_Tp, _Compare, _Allocator>::iterator
-__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args) {
__node_holder __h = __construct_node(std::forward<_Args>(__args)...);
__parent_pointer __parent;
__node_base_pointer __dummy;
@@ -1847,7 +1850,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p
template <class _Tp, class _Compare, class _Allocator>
template <class... _Args>
typename __tree<_Tp, _Compare, _Allocator>::iterator
-__tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) {
__node_holder __h = __construct_node(std::forward<_Args>(__args)...);
__parent_pointer __parent;
__node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__h->__value_));
@@ -1858,7 +1861,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) {
template <class _Tp, class _Compare, class _Allocator>
template <class... _Args>
typename __tree<_Tp, _Compare, _Allocator>::iterator
-__tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) {
__node_holder __h = __construct_node(std::forward<_Args>(__args)...);
__parent_pointer __parent;
__node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__h->__value_));
diff --git a/libcxx/include/map b/libcxx/include/map
index 3ae485f1ce029..92891332c3a57 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -639,21 +639,21 @@ template <class _Key,
bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
class __map_value_compare : private _Compare {
public:
- _LIBCPP_HIDE_FROM_ABI __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
: _Compare() {}
- _LIBCPP_HIDE_FROM_ABI __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
: _Compare(__c) {}
- _LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return *this; }
- _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const _Compare& key_comp() const _NOEXCEPT { return *this; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _CP& __x, const _CP& __y) const {
return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);
}
- _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _CP& __x, const _Key& __y) const {
return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
}
- _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _Key& __x, const _CP& __y) const {
return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
}
- _LIBCPP_HIDE_FROM_ABI void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Compare>) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Compare>) {
using std::swap;
swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
}
@@ -868,37 +868,37 @@ public:
typedef value_type& reference;
typedef typename _NodeTypes::__map_value_type_pointer pointer;
- _LIBCPP_HIDE_FROM_ABI __map_iterator() _NOEXCEPT {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator() _NOEXCEPT {}
- _LIBCPP_HIDE_FROM_ABI __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
- _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
- _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __i_->__get_value(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
- _LIBCPP_HIDE_FROM_ABI __map_iterator& operator++() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator& operator++() {
++__i_;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __map_iterator operator++(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator operator++(int) {
__map_iterator __t(*this);
++(*this);
return __t;
}
- _LIBCPP_HIDE_FROM_ABI __map_iterator& operator--() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator& operator--() {
--__i_;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __map_iterator operator--(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_iterator operator--(int) {
__map_iterator __t(*this);
--(*this);
return __t;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_iterator& __x, const __map_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const __map_iterator& __x, const __map_iterator& __y) {
return __x.__i_ == __y.__i_;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {
return __x.__i_ != __y.__i_;
}
@@ -924,39 +924,39 @@ public:
typedef const value_type& reference;
typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
- _LIBCPP_HIDE_FROM_ABI __map_const_iterator() _NOEXCEPT {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator() _NOEXCEPT {}
- _LIBCPP_HIDE_FROM_ABI __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
_LIBCPP_HIDE_FROM_ABI
- __map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {}
+ _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {}
- _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
- _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator*() const { return __i_->__get_value(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
- _LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator++() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator& operator++() {
++__i_;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __map_const_iterator operator++(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator operator++(int) {
__map_const_iterator __t(*this);
++(*this);
return __t;
}
- _LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator--() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator& operator--() {
--__i_;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __map_const_iterator operator--(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __map_const_iterator operator--(int) {
__map_const_iterator __t(*this);
--(*this);
return __t;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) {
return __x.__i_ == __y.__i_;
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {
return __x.__i_ != __y.__i_;
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp
index 21118eca69693..247ac1895b4f3 100644
--- a/libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// bool empty() const;
+// bool empty() const;// constexpr since C++26
#include <map>
#include <cassert>
@@ -18,7 +18,7 @@
#include "test_macros.h"
#include "min_allocator.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::map<int, double> M;
M m;
@@ -39,6 +39,13 @@ int main(int, char**) {
assert(m.empty());
}
#endif
+return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/empty.verify.cpp b/libcxx/test/std/containers/associative/map/map.access/empty.verify.cpp
index f44411df0bb00..269add6089628 100644
--- a/libcxx/test/std/containers/associative/map/map.access/empty.verify.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/empty.verify.cpp
@@ -10,13 +10,21 @@
// class map
-// bool empty() const noexcept;
+// bool empty() const noexcept;// constexpr since C++26
// UNSUPPORTED: c++03, c++11, c++14, c++17
#include <map>
-void f() {
+bool test() {
std::map<int, int> c;
c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ return true;
+}
+
+int main() {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp
index 58610c69ed3dc..8633d522947c5 100644
--- a/libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// mapped_type& operator[](const key_type& k);
+// mapped_type& operator[](const key_type& k);// constexpr since C++26
#include <map>
#include <cassert>
@@ -23,7 +23,7 @@
# include "container_test_types.h"
#endif
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::pair<const int, double> V;
V ar[] = {
@@ -135,6 +135,13 @@ int main(int, char**) {
assert(m.size() == 8);
}
#endif
+return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp
index d5d01b96a6988..f5ec0c73bd284 100644
--- a/libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp
@@ -12,7 +12,7 @@
// class map
-// mapped_type& operator[](key_type&& k);
+// mapped_type& operator[](key_type&& k);// constexpr since C++26
#include <map>
#include <cassert>
@@ -23,7 +23,7 @@
#include "min_allocator.h"
#include "container_test_types.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
std::map<MoveOnly, double> m;
assert(m.size() == 0);
@@ -75,6 +75,13 @@ int main(int, char**) {
}
}
}
+return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp
index 3f33cfd699151..565db2b6b7342 100644
--- a/libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp
@@ -12,16 +12,23 @@
// class map
-// mapped_type& operator[](const key_type& k);
+// mapped_type& operator[](const key_type& k);// constexpr since C++26
// https://llvm.org/PR16542
#include <map>
#include <tuple>
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
std::map<std::tuple<int, int>, std::size_t> m;
m[std::make_tuple(2, 3)] = 7;
+return true;
+}
+int main(int, char**) {
+assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp
index bbad44c8edb30..20f8541213007 100644
--- a/libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp
@@ -10,20 +10,20 @@
// class map
-// iterator begin();
-// const_iterator begin() const;
-// iterator end();
-// const_iterator end() const;
+// iterator begin();// constexpr since C++26
+// const_iterator begin() const;// constexpr since C++26
+// iterator end();// constexpr since C++26
+// const_iterator end() const;// constexpr since C++26
//
-// reverse_iterator rbegin();
-// const_reverse_iterator rbegin() const;
-// reverse_iterator rend();
-// const_reverse_iterator rend() const;
+// reverse_iterator rbegin();// constexpr since C++26
+// const_reverse_iterator rbegin() const;// constexpr since C++26
+// reverse_iterator rend();// constexpr since C++26
+// const_reverse_iterator rend() const;// constexpr since C++26
//
-// const_iterator cbegin() const;
-// const_iterator cend() const;
-// const_reverse_iterator crbegin() const;
-// const_reverse_iterator crend() const;
+// const_iterator cbegin() const;// constexpr since C++26
+// const_iterator cend() const;// constexpr since C++26
+// const_reverse_iterator crbegin() const;// constexpr since C++26
+// const_reverse_iterator crend() const;// constexpr since C++26
#include <map>
#include <cassert>
@@ -32,7 +32,7 @@
#include "test_macros.h"
#include "min_allocator.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::pair<const int, double> V;
V ar[] = {V(1, 1), V(1, 1.5), V(1, 2), V(2, 1), V(2, 1.5), V(2, 2), V(3, 1), V(3, 1.5),
@@ -156,6 +156,13 @@ int main(int, char**) {
assert(!(cii != ii1));
}
#endif
+return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp
index 1a5d35c2579d8..3a552cebd1fb4 100644
--- a/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// size_type max_size() const;
+// size_type max_size() const;// constexpr since C++26
#include <cassert>
#include <limits>
@@ -20,7 +20,7 @@
#include "test_allocator.h"
#include "test_macros.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
typedef std::pair<const int, int> KV;
{
typedef limited_allocator<KV, 10> A;
@@ -44,6 +44,13 @@ int main(int, char**) {
assert(c.max_size() <= max_dist);
assert(c.max_size() <= alloc_max_size(c.get_allocator()));
}
+return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.access/size.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/size.pass.cpp
index 23914f6b8ed16..cfb3d6e9426df 100644
--- a/libcxx/test/std/containers/associative/map/map.access/size.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/size.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// size_type size() const;
+// size_type size() const;// constexpr since C++26
#include <map>
#include <cassert>
@@ -18,7 +18,7 @@
#include "test_macros.h"
#include "min_allocator.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::map<int, double> M;
M m;
@@ -55,6 +55,13 @@ int main(int, char**) {
assert(m.size() == 0);
}
#endif
+return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp
index f237c9b56deee..9b1f9730591f3 100644
--- a/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp
@@ -12,7 +12,7 @@
// class map
-// map& operator=(initializer_list<value_type> il);
+// map& operator=(initializer_list<value_type> il);// constexpr since C++26
#include <map>
#include <cassert>
@@ -21,7 +21,7 @@
#include "min_allocator.h"
#include "test_allocator.h"
-void test_basic() {
+TEST_CONSTEXPR_CXX26 bool test_basic() {
{
typedef std::pair<const int, double> V;
std::map<int, double> m = {
@@ -46,9 +46,10 @@ void test_basic() {
assert(*std::next(m.begin()) == V(2, 1));
assert(*std::next(m.begin(), 2) == V(3, 1));
}
+ return true;
}
-void duplicate_keys_test() {
+TEST_CONSTEXPR_CXX26 bool duplicate_keys_test() {
test_allocator_statistics alloc_stats;
typedef std::map<int, int, std::less<int>, test_allocator<std::pair<const int, int> > > Map;
{
@@ -61,11 +62,19 @@ void duplicate_keys_test() {
assert(s.begin()->first == 4);
}
LIBCPP_ASSERT(alloc_stats.alloc_count == 0);
+ return true;
}
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
test_basic();
duplicate_keys_test();
+return true;
+}
+int main(int, char**) {
+ assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp
index bd27a2f4ddeb9..66696da0fd39f 100644
--- a/libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// explicit map(const key_compare& comp);
+// explicit map(const key_compare& comp);// constexpr since C++26
#include <map>
#include <cassert>
@@ -19,7 +19,7 @@
#include "../../../test_compare.h"
#include "min_allocator.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef test_less<int> C;
const std::map<int, double, C> m(C(3));
@@ -36,6 +36,13 @@ int main(int, char**) {
assert(m.key_comp() == C(3));
}
#endif
+return true;
+}
+int main(int, char**) {
+assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp
index 20f6a08db6a36..19b294573fc58 100644
--- a/libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// map(const key_compare& comp, const allocator_type& a);
+// map(const key_compare& comp, const allocator_type& a);// constexpr since C++26
#include <map>
#include <cassert>
@@ -20,7 +20,7 @@
#include "test_allocator.h"
#include "min_allocator.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef test_less<int> C;
typedef test_allocator<std::pair<const int, double> > A;
@@ -50,6 +50,13 @@ int main(int, char**) {
assert(m.get_allocator() == A{});
}
#endif
+return true;
+}
+int main(int, char**) {
+assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp
index aaf1be867b748..ffb99c9edd1f0 100644
--- a/libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp
@@ -10,7 +10,7 @@
// class map
-// map(const map& m, const allocator_type& a);
+// map(const map& m, const allocator_type& a);// constexpr since C++26
#include <map>
#include <cassert>
@@ -20,7 +20,7 @@
#include "test_allocator.h"
#include "min_allocator.h"
-int main(int, char**) {
+TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::pair<const int, double> V;
V ar[] = {
@@ -122,6 +122,13 @@ int main(int, char**) {
assert(*std::next(mo.begin(), 2) == V(3, 1));
}
#endif
+return true;
+}
+int main(int, char**) {
+assert(test());
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
>From ec9317e498e0f780a5e317ff1da6fe8874f0d104 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sat, 5 Apr 2025 20:28:45 -0400
Subject: [PATCH 06/11] Move past member call on object past it's lifetime
---
libcxx/include/__tree | 10 ++++++++--
libcxx/include/map | 18 ++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index c966236e51842..d8c22cbcb2c4e 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -543,7 +543,11 @@ struct __tree_key_value_types<__value_type<_Key, _Tp> > {
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static __container_value_type* __get_ptr(__node_value_type& __n) {
- return std::addressof(__n.__get_value());
+ // __n's lifetime has not begun, so calling __get_value is wrong
+
+ // return std::addressof(__n.__get_value());
+
+ return __node_value_type::__get_address_of_value(__n);
}
_LIBCPP_HIDE_FROM_ABI static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { return __v.__move(); }
@@ -658,6 +662,7 @@ public:
__node_value_type __value_;
_LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
+ // _LIBCPP_HIDE_FROM_ABI static _Tp& __get_value_static(__tree_node * foo) { return (foo->__value_); }
~__tree_node() = delete;
__tree_node(__tree_node const&) = delete;
@@ -1816,8 +1821,9 @@ __tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) {
template <class _Tp, class _Compare, class _Allocator>
template <class... _Args>
+_LIBCPP_CONSTEXPR_SINCE_CXX26
pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
-_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) {
+__tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) {
__node_holder __h = __construct_node(std::forward<_Args>(__args)...);
__parent_pointer __parent;
__node_base_pointer& __child = __find_equal(__parent, __h->__value_);
diff --git a/libcxx/include/map b/libcxx/include/map
index 92891332c3a57..5cefee5b0092d 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -790,6 +790,17 @@ public:
# endif
}
+
+ /*
+ Use this helper when the lifetime of __v may not have begun,
+ so calling __v.__get_value() is not allowed
+ as per:
+ `note: member call on object outside its lifetime is not allowed in a constant expression`
+ */
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static value_type* __get_address_of_value(__value_type & __v) {
+ return std::addressof(__v.__cc_);
+ }
+
_LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
value_type& __v = __get_value();
return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
@@ -837,6 +848,13 @@ public:
_LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
_LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
+
+ // TODO: maybe needed
+ // _LIBCPP_HIDE_FROM_ABI static value_type* __get_address_of_value(__value_type const& __v) {
+ // return std::addressof(__v.__cc_);
+ // }
+
+
__value_type() = delete;
__value_type(__value_type const&) = delete;
__value_type& operator=(__value_type const&) = delete;
>From cec33fbe71a41b45008e281d523146805eb6e37d Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 6 Apr 2025 00:54:56 -0400
Subject: [PATCH 07/11] Add ctor to initialize __value_type and
__tree_node_base, and the object of unique_ptr
---
libcxx/include/__tree | 20 ++++++++++++++++++--
libcxx/include/map | 5 ++++-
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index d8c22cbcb2c4e..f3d36c0b9db52 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -649,7 +649,10 @@ public:
_LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__parent_pointer>(__p); }
- ~__tree_node_base() = delete;
+
+ // template <typename... Args> constexpr __tree_node_base(Args && ... args) =default;
+ __tree_node_base() = default;
+ ~__tree_node_base() = default;
__tree_node_base(__tree_node_base const&) = delete;
__tree_node_base& operator=(__tree_node_base const&) = delete;
};
@@ -664,6 +667,10 @@ public:
_LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
// _LIBCPP_HIDE_FROM_ABI static _Tp& __get_value_static(__tree_node * foo) { return (foo->__value_); }
+
+ template <typename... Args> constexpr __tree_node(Args && ... args): __value_{std::forward<Args>(args)...} { }
+ // TODO: libcxx26
+ // _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree_node(__node_value_type && args): __value_{args} { }
~__tree_node() = delete;
__tree_node(__tree_node const&) = delete;
__tree_node& operator=(__tree_node const&) = delete;
@@ -1814,7 +1821,16 @@ __tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) {
static_assert(!__is_tree_value_type<_Args...>::value, "Cannot construct from __value_type");
__node_allocator& __na = __node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
- __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), std::forward<_Args>(__args)...);
+ // std::__value_type<int, double>
+ // __h->__value_;
+// std::addresof(__h->__value_);
+
+ // __node_traits::construct(__na, std::addressof(__h->__value_), std::forward<_Args>(__args)...);
+ // *h is allocated as of yet, but not constructed
+ // TODO: -> remove (AFAIK, given only cc in the following needs space: h, h->value and h->value->cc)
+ __node_traits::construct(__na, std::addressof(*__h), std::forward<_Args>(__args)...);
+
+ // __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), std::forward<_Args>(__args)...);
__h.get_deleter().__value_constructed = true;
return __h;
}
diff --git a/libcxx/include/map b/libcxx/include/map
index 5cefee5b0092d..e363d2ed84c79 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -827,8 +827,11 @@ public:
return *this;
}
+ // TODO: libcxx26
+ template <typename... Args> _LIBCPP_CONSTEXPR_SINCE_CXX26 __value_type(Args && ... args): __cc_{std::forward<Args>(args)...} { }
+ // constexpr __value_type(value_type && args): __cc_{args} { }
__value_type() = delete;
- ~__value_type() = delete;
+ ~__value_type() = default;
__value_type(const __value_type&) = delete;
__value_type(__value_type&&) = delete;
};
>From 0574be6138c0ac6777b9e267e815335a3a76a0f3 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 6 Apr 2025 10:00:53 -0400
Subject: [PATCH 08/11] construction works, at() fails due to
throw_out_of_range
---
libcxx/include/__tree | 30 +++++++++++++++---------------
libcxx/include/map | 5 +++--
libcxx/include/stdexcept | 6 +++---
3 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index f3d36c0b9db52..2895364af3be3 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -98,7 +98,7 @@ __root, have a non-null __parent_ field.
// Returns: true if __x is a left child of its parent, else false
// Precondition: __x != nullptr.
template <class _NodePtr>
-inline _LIBCPP_HIDE_FROM_ABI bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT {
return __x == __x->__parent_->__left_;
}
@@ -164,7 +164,7 @@ inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_min(_NodePtr __x) _NOEXCEPT {
// Returns: pointer to the right-most node under __x.
template <class _NodePtr>
-inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Root node shouldn't be null");
while (__x->__right_ != nullptr)
__x = __x->__right_;
@@ -195,7 +195,7 @@ inline _LIBCPP_HIDE_FROM_ABI _EndNodePtr __tree_next_iter(_NodePtr __x) _NOEXCEP
// Returns: pointer to the previous in-order node before __x.
// Note: __x may be the end node.
template <class _NodePtr, class _EndNodePtr>
-inline _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT {
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null");
if (__x->__left_ != nullptr)
return std::__tree_max(__x->__left_);
@@ -226,7 +226,7 @@ _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_leaf(_NodePtr __x) _NOEXCEPT {
// Effects: Makes __x->__right_ the subtree root with __x as its left child
// while preserving in-order order.
template <class _NodePtr>
-_LIBCPP_HIDE_FROM_ABI void __tree_left_rotate(_NodePtr __x) _NOEXCEPT {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree_left_rotate(_NodePtr __x) _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null");
_LIBCPP_ASSERT_INTERNAL(__x->__right_ != nullptr, "node should have a right child");
_NodePtr __y = __x->__right_;
@@ -269,7 +269,7 @@ _LIBCPP_HIDE_FROM_ABI void __tree_right_rotate(_NodePtr __x) _NOEXCEPT {
// Postcondition: __tree_invariant(end_node->__left_) == true. end_node->__left_
// may be different than the value passed in as __root.
template <class _NodePtr>
-_LIBCPP_HIDE_FROM_ABI void __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(__root != nullptr, "Root of the tree shouldn't be null");
_LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Can't attach null node to a leaf");
__x->__is_black_ = __x == __root;
@@ -645,9 +645,9 @@ public:
__parent_pointer __parent_;
bool __is_black_;
- _LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const { return static_cast<pointer>(__parent_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pointer __parent_unsafe() const { return static_cast<pointer>(__parent_); }
- _LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__parent_pointer>(__p); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set_parent(pointer __p) { __parent_ = static_cast<__parent_pointer>(__p); }
// template <typename... Args> constexpr __tree_node_base(Args && ... args) =default;
@@ -960,19 +960,19 @@ public:
_LIBCPP_HIDE_FROM_ABI allocator_type __alloc() const _NOEXCEPT { return allocator_type(__node_alloc()); }
private:
- _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type& size() _NOEXCEPT { return __size_; }
public:
- _LIBCPP_HIDE_FROM_ABI const size_type& size() const _NOEXCEPT { return __size_; }
- _LIBCPP_HIDE_FROM_ABI value_compare& value_comp() _NOEXCEPT { return __value_comp_; }
- _LIBCPP_HIDE_FROM_ABI const value_compare& value_comp() const _NOEXCEPT { return __value_comp_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const size_type& size() const _NOEXCEPT { return __size_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare& value_comp() _NOEXCEPT { return __value_comp_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const value_compare& value_comp() const _NOEXCEPT { return __value_comp_; }
public:
- _LIBCPP_HIDE_FROM_ABI __node_pointer __root() const _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_pointer __root() const _NOEXCEPT {
return static_cast<__node_pointer>(__end_node()->__left_);
}
- _LIBCPP_HIDE_FROM_ABI __node_base_pointer* __root_ptr() const _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_base_pointer* __root_ptr() const _NOEXCEPT {
return std::addressof(__end_node()->__left_);
}
@@ -1183,7 +1183,7 @@ public:
template <class _Key>
_LIBCPP_HIDE_FROM_ABI size_type __erase_multi(const _Key& __k);
- _LIBCPP_HIDE_FROM_ABI void
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
__insert_node_at(__parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT;
template <class _Key>
@@ -1764,7 +1764,7 @@ typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Co
}
template <class _Tp, class _Compare, class _Allocator>
-void __tree<_Tp, _Compare, _Allocator>::__insert_node_at(
+_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::__insert_node_at(
__parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT {
__new_node->__left_ = nullptr;
__new_node->__right_ = nullptr;
diff --git a/libcxx/include/map b/libcxx/include/map
index e363d2ed84c79..3aaccf2e0f3d9 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -774,7 +774,7 @@ private:
value_type __cc_;
public:
- _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_type& __get_value() {
# if _LIBCPP_STD_VER >= 17
return *std::launder(std::addressof(__cc_));
# else
@@ -782,7 +782,7 @@ public:
# endif
}
- _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const value_type& __get_value() const {
# if _LIBCPP_STD_VER >= 17
return *std::launder(std::addressof(__cc_));
# else
@@ -791,6 +791,7 @@ public:
}
+ // TODO: possibly no longer needed
/*
Use this helper when the lifetime of __v may not have begun,
so calling __v.__get_value() is not allowed
diff --git a/libcxx/include/stdexcept b/libcxx/include/stdexcept
index 85e11629bd6e3..29d5083ac1c31 100644
--- a/libcxx/include/stdexcept
+++ b/libcxx/include/stdexcept
@@ -161,8 +161,8 @@ public:
class _LIBCPP_EXPORTED_FROM_ABI out_of_range : public logic_error {
public:
- _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const string& __s) : logic_error(__s) {}
- _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const char* __s) : logic_error(__s) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit out_of_range(const string& __s) : logic_error(__s) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit out_of_range(const char* __s) : logic_error(__s) {}
# ifndef _LIBCPP_ABI_VCRUNTIME
_LIBCPP_HIDE_FROM_ABI out_of_range(const out_of_range&) _NOEXCEPT = default;
@@ -246,7 +246,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
# endif
}
-[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {
+[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __throw_out_of_range(const char* __msg) {
# if _LIBCPP_HAS_EXCEPTIONS
throw out_of_range(__msg);
# else
>From ed995a22d6d8608be504a01f52007d3866a0636c Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 6 Apr 2025 10:14:21 -0400
Subject: [PATCH 09/11] can't intentionally throw in constexpr
---
.../std/containers/associative/map/map.access/at.pass.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
index 26a0ad1ff1613..130eefe990363 100644
--- a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
@@ -42,11 +42,16 @@ TEST_CONSTEXPR_CXX26 bool test() {
assert(m.at(4) == 4.5);
assert(m.at(5) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
+
+// throwing is not allowed in constexpr
+#if TEST_STD_VER < 26
try {
TEST_IGNORE_NODISCARD m.at(6);
assert(false);
} catch (std::out_of_range&) {
}
+#endif
+
#endif
assert(m.at(7) == 7.5);
assert(m.at(8) == 8.5);
>From e941811243219e2eb3637a0c5dc3ba078b9d63f4 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 6 Apr 2025 10:18:29 -0400
Subject: [PATCH 10/11] note: cast from 'void *' is not allowed in a constant
expression because the pointed object type
'std::__tree_node<std::__value_type<int, double>, min_pointer<void>>' is not
similar to the target type 'std::__tree_node_base<min_pointer<void>>'
---
libcxx/include/__tree | 4 ++--
.../std/containers/associative/map/map.access/at.pass.cpp | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 2895364af3be3..cfdd1f6ca8f2b 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -1270,7 +1270,7 @@ private:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __node_holder __construct_node(_Args&&... __args);
// TODO: Make this _LIBCPP_HIDE_FROM_ABI
- _LIBCPP_HIDDEN void destroy(__node_pointer __nd) _NOEXCEPT;
+ _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX26 void destroy(__node_pointer __nd) _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, false_type);
_LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, true_type) _NOEXCEPT_(
@@ -1540,7 +1540,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::~__tree() {
}
template <class _Tp, class _Compare, class _Allocator>
-void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT {
+_LIBCPP_CONSTEXPR_SINCE_CXX26 void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT {
if (__nd != nullptr) {
destroy(static_cast<__node_pointer>(__nd->__left_));
destroy(static_cast<__node_pointer>(__nd->__right_));
diff --git a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
index 130eefe990363..3a761dd109410 100644
--- a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
@@ -75,13 +75,15 @@ TEST_CONSTEXPR_CXX26 bool test() {
assert(m.at(3) == 3.5);
assert(m.at(4) == 4.5);
assert(m.at(5) == 5.5);
-#ifndef TEST_HAS_NO_EXCEPTIONS
+// throwing is not allowed in constexpr
+#if TEST_STD_VER < 26
try {
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);
>From def82612573b3b5fe13dac573e58f6dd12c8b347 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Sun, 6 Apr 2025 14:24:43 -0400
Subject: [PATCH 11/11] note: cast from 'void *' is not allowed in a constant
expression because the pointed object type
'std::__tree_node<std::__value_type<int, double>, min_pointer<void>>' is not
similar to the target type 'std::__tree_node_base<min_pointer<void>>
---
libcxx/include/__tree | 53 +++++++++++++++++++
.../associative/map/map.access/at.pass.cpp | 20 +++++++
2 files changed, 73 insertions(+)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index cfdd1f6ca8f2b..bcc0b58c464f2 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -1800,12 +1800,65 @@ pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
_LIBCPP_CONSTEXPR_SINCE_CXX26 __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
const_iterator __p, _Key const& __k, _Args&&... __args) {
__parent_pointer __parent;
+ // std::__tree_end_node<std::__tree_node_base<void *> *>
__node_base_pointer __dummy;
+ // min_pointer<std::__tree_node_base<min_pointer<void>>>
+
__node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __k);
__node_pointer __r = static_cast<__node_pointer>(__child);
bool __inserted = false;
if (__child == nullptr) {
__node_holder __h = __construct_node(std::forward<_Args>(__args)...);
+ // std::unique_ptr<std::__tree_node<std::__value_type<int, double>, min_pointer<void>>, std::__tree_node_destructor<min_allocator<std::__tree_node<std::__value_type<int, double>, min_pointer<void>>>>>
+
+ // *h
+ // std::__tree_node<std::__value_type<int, double>, min_pointer<void>>
+ // (*__h).fooooo;
+ // std::__tree_node<std::__value_type<int, double>, min_pointer<void>>
+
+ // __h.get().foooooo;
+ // min_pointer<std::__tree_node<std::__value_type<int, double>, min_pointer<void>>>
+
+ // __node_base_pointer = min_pointer<std::__tree_node_base< min_pointer<void>>>
+ // __h.get() = min_pointer<std::__tree_node <std::__value_type<int, double>, min_pointer<void>>>
+
+
+ // static_assert();
+
+ // __tree_node::__node_value_type = std::__value_type<int, double>
+
+ /*
+ without 233
+ no matching conversion for static_cast
+ from 'pointer' (aka
+ 'min_pointer<std::__tree_node<std::__value_type<int, double>, min_pointer<void, std::integral_constant<unsigned long, 0>>>>'
+ )
+ to '__node_base_pointer' (aka
+ 'min_pointer<std::__tree_node_base<min_pointer<void, std::integral_constant<unsigned long, 0>>>, std::integral_constant<unsigned long, 0>>'
+ )
+ */
+
+
+
+
+ [[maybe_unused]] __node_base_pointer foo = static_cast<__node_base_pointer>(__h.get());
+ // [[maybe_unused]] __node_base_pointer foo2 = __node_base_pointer(__h.get());
+
+
+
+
+ /*
+ note:
+ cast from 'void *' is not allowed in a constant expression
+ because the pointed object type
+ 'std::__tree_node<std::__value_type<int, double>, min_pointer<void>>'
+ is not similar to the target type
+ 'std::__tree_node_base<min_pointer<void>>'
+ */
+
+// i believe this cast fails because the lifetime of __h.get() has not begun
+
+
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
__r = __h.release();
__inserted = true;
diff --git a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
index 3a761dd109410..98235061da5c8 100644
--- a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp
@@ -16,6 +16,7 @@
#include <cassert>
#include <map>
#include <stdexcept>
+#include <type_traits>
#include "min_allocator.h"
#include "test_macros.h"
@@ -100,6 +101,25 @@ TEST_CONSTEXPR_CXX26 bool test() {
V(7, 7.5),
V(8, 8.5),
};
+
+ // std::__tree_node<std::__value_type<int,double>, min_pointer<void>> d;
+ // std::__tree_node_base<min_pointer<void>> b = d;
+ using Base = std::__tree_node_base<min_pointer<void>>;
+
+ using Derived = std::__tree_node<std::__value_type<int,double>, min_pointer<void>> ;
+ static_assert(std::is_base_of_v<Base, Derived>);
+
+
+ using BaseP = min_pointer<Base>;
+ using DerivedP = min_pointer<Derived>;
+ // static_assert(std::is_base_of_v<BaseP, DerivedP>);
+ DerivedP dp(nullptr);
+
+ BaseP bp =static_cast<BaseP>(dp);
+ (void)bp;
+
+
+
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);
More information about the libcxx-commits
mailing list