Skip to content

[libc++] constexpr deque #129368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_constexpr_algorithms`` ``202306L``
---------------------------------------------------------- -----------------
``__cpp_lib_constexpr_deque`` ``202502L``
---------------------------------------------------------- -----------------
``__cpp_lib_constexpr_new`` ``202406L``
---------------------------------------------------------- -----------------
``__cpp_lib_constrained_equality`` *unimplemented*
Expand Down
122 changes: 72 additions & 50 deletions libcxx/include/deque
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ private:

public:
// construct/copy/destroy:
_LIBCPP_HIDE_FROM_ABI deque() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 deque()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __start_(0), __size_(0) {
__annotate_new(0);
}
Expand All @@ -619,19 +620,20 @@ public:
__alloc_traits::deallocate(__alloc(), *__i, __block_size);
}

_LIBCPP_HIDE_FROM_ABI explicit deque(const allocator_type& __a)
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit deque(const allocator_type& __a)
: __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
__annotate_new(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frederick-vs-ja when trying to call the test in a constexpr case, via static_assert, I got error that __annotate_new (0) cannot be used in a constant expression, this function is called within a constexpr constructor. How should I handle this case? Can __annotate_new be made constexpr ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think we can mark most underlying ASAN-related functions (which are not previously constexpr) _LIBCPP_CONSTEXPR_SINCE_CXX26 and add if (__libcpp_is_constant_evaluated()) return; to suitable places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frederick-vs-ja can you give me an example of where I can put if (__libcpp_is_constant_evaluated()) return; ? I am not sure how I can apply that function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error messages look a bit chaotic. Could you try again after finish adding _LIBCPP_CONSTEXPR_SINCE_CXX26 to <deque>?

}

explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n);
# if _LIBCPP_STD_VER >= 14
explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const _Allocator& __a);
explicit _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 deque(size_type __n, const _Allocator& __a);
# endif
_LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v);

template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v, const allocator_type& __a)
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
deque(size_type __n, const value_type& __v, const allocator_type& __a)
: __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
__annotate_new(0);
if (__n > 0)
Expand All @@ -641,11 +643,12 @@ public:
template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI deque(_InputIter __f, _InputIter __l);
template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI deque(_InputIter __f, _InputIter __l, const allocator_type& __a);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 deque(_InputIter __f, _InputIter __l, const allocator_type& __a);

# if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<_Tp> _Range>
_LIBCPP_HIDE_FROM_ABI deque(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
deque(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
: __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
__append_with_size(ranges::begin(__range), ranges::distance(__range));
Expand All @@ -658,22 +661,24 @@ public:
}
# endif

_LIBCPP_HIDE_FROM_ABI deque(const deque& __c);
_LIBCPP_HIDE_FROM_ABI deque(const deque& __c, const __type_identity_t<allocator_type>& __a);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 deque(const deque& __c);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
deque(const deque& __c, const __type_identity_t<allocator_type>& __a);

_LIBCPP_HIDE_FROM_ABI deque& operator=(const deque& __c);

# ifndef _LIBCPP_CXX03_LANG
_LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il);
_LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il, const allocator_type& __a);

_LIBCPP_HIDE_FROM_ABI deque& operator=(initializer_list<value_type> __il) {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 deque& operator=(initializer_list<value_type> __il) {
assign(__il);
return *this;
}

_LIBCPP_HIDE_FROM_ABI deque(deque&& __c) noexcept(is_nothrow_move_constructible<allocator_type>::value);
_LIBCPP_HIDE_FROM_ABI deque(deque&& __c, const __type_identity_t<allocator_type>& __a);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
deque(deque&& __c) noexcept(is_nothrow_move_constructible<allocator_type>::value);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 deque(deque&& __c, const __type_identity_t<allocator_type>& __a);
_LIBCPP_HIDE_FROM_ABI deque& operator=(deque&& __c) noexcept(
(__alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value) ||
Expand Down Expand Up @@ -709,67 +714,81 @@ public:

_LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v);

_LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 allocator_type get_allocator() const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; }
_LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; }

// iterators:

_LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator begin() _NOEXCEPT {
__map_pointer __mp = __map_.begin() + __start_ / __block_size;
return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
}

_LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator begin() const _NOEXCEPT {
__map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
}

_LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator end() _NOEXCEPT {
size_type __p = size() + __start_;
__map_pointer __mp = __map_.begin() + __p / __block_size;
return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
}

_LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator end() const _NOEXCEPT {
size_type __p = size() + __start_;
__map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size);
return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
}

_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 const_reverse_iterator(end()); }
_LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
_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 const_reverse_iterator(end());
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crend() const _NOEXCEPT {
return const_reverse_iterator(begin());
}

// capacity:
_LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size(); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type size() const _NOEXCEPT { return __size(); }

_LIBCPP_HIDE_FROM_ABI size_type& __size() _NOEXCEPT { return __size_; }
_LIBCPP_HIDE_FROM_ABI const size_type& __size() const _NOEXCEPT { return __size_; }

_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>(__alloc_traits::max_size(__alloc()), numeric_limits<difference_type>::max());
}
_LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
_LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __v);
_LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void resize(size_type __n);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void resize(size_type __n, const value_type& __v);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void shrink_to_fit() _NOEXCEPT;
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool empty() const _NOEXCEPT {
return size() == 0;
}

// element access:
_LIBCPP_HIDE_FROM_ABI reference operator[](size_type __i) _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __i) const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI reference at(size_type __i);
_LIBCPP_HIDE_FROM_ABI const_reference at(size_type __i) const;
_LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference operator[](size_type __i) _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reference operator[](size_type __i) const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference at(size_type __i);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reference at(size_type __i) const;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference front() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reference front() const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reference back() _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reference back() const _NOEXCEPT;

// 23.2.2.3 modifiers:
_LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v);
Expand All @@ -789,8 +808,8 @@ public:
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);

_LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v);
_LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __v);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void push_front(value_type&& __v);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void push_back(value_type&& __v);

# if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<_Tp> _Range>
Expand Down Expand Up @@ -1570,7 +1589,7 @@ inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::
}

template <class _Tp, class _Allocator>
void deque<_Tp, _Allocator>::push_back(const value_type& __v) {
void _LIBCPP_CONSTEXPR_SINCE_CXX26 deque<_Tp, _Allocator>::push_back(const value_type& __v) {
allocator_type& __a = __alloc();
if (__back_spare() == 0)
__add_back_capacity();
Expand Down Expand Up @@ -1658,7 +1677,8 @@ deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) {
}

template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) {
_LIBCPP_CONSTEXPR_SINCE_CXX26 typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) {
size_type __pos = __p - begin();
size_type __to_end = size() - __pos;
allocator_type& __a = __alloc();
Expand Down Expand Up @@ -1755,7 +1775,8 @@ typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::emplace(const_
# endif // _LIBCPP_CXX03_LANG

template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) {
_LIBCPP_CONSTEXPR_SINCE_CXX26 typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) {
size_type __pos = __p - begin();
size_type __to_end = size() - __pos;
allocator_type& __a = __alloc();
Expand Down Expand Up @@ -1807,7 +1828,7 @@ typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_i
}

template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
typename deque<_Tp, _Allocator>::iterator _LIBCPP_CONSTEXPR_SINCE_CXX26
deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) {
size_type __pos = __p - begin();
size_type __to_end = __size() - __pos;
Expand Down Expand Up @@ -2543,7 +2564,8 @@ inline void deque<_Tp, _Allocator>::clear() _NOEXCEPT {
}

template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI bool operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool
operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
const typename deque<_Tp, _Allocator>::size_type __sz = __x.size();
return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
}
Expand Down Expand Up @@ -2578,30 +2600,30 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const deque<_Tp, _Allocator>& __x,
# else // _LIBCPP_STD_VER <= 17

template <class _Tp, class _Allocator>
_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __synth_three_way_result<_Tp>
operator<=>(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
}

# endif // _LIBCPP_STD_VER <= 17

template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI void swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
__x.swap(__y);
}

# if _LIBCPP_STD_VER >= 20
template <class _Tp, class _Allocator, class _Up>
inline _LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::size_type
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 typename deque<_Tp, _Allocator>::size_type
erase(deque<_Tp, _Allocator>& __c, const _Up& __v) {
auto __old_size = __c.size();
__c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
return __old_size - __c.size();
}

template <class _Tp, class _Allocator, class _Predicate>
inline _LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::size_type
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 typename deque<_Tp, _Allocator>::size_type
erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) {
auto __old_size = __c.size();
__c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
Expand Down
2 changes: 2 additions & 0 deletions libcxx/include/version
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ __cpp_lib_constexpr_bitset 202207L <bitset>
__cpp_lib_constexpr_charconv 202207L <charconv>
__cpp_lib_constexpr_cmath 202202L <cmath> <cstdlib>
__cpp_lib_constexpr_complex 201711L <complex>
__cpp_lib_constexpr_deque 202502L <deque>
__cpp_lib_constexpr_dynamic_alloc 201907L <memory>
__cpp_lib_constexpr_functional 201907L <functional>
__cpp_lib_constexpr_iterator 201811L <iterator>
Expand Down Expand Up @@ -539,6 +540,7 @@ __cpp_lib_void_t 201411L <type_traits>
# define __cpp_lib_bitset 202306L
# undef __cpp_lib_constexpr_algorithms
# define __cpp_lib_constexpr_algorithms 202306L
# define __cpp_lib_constexpr_deque 202502L
# if !defined(_LIBCPP_ABI_VCRUNTIME)
# define __cpp_lib_constexpr_new 202406L
# endif
Expand Down
10 changes: 9 additions & 1 deletion libcxx/test/std/containers/sequences/deque/compare.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "test_comparisons.h"

int main(int, char**) {
TEST_CONSTEXPR_CXX26 bool test() {
{
const std::deque<int> d1, d2;
assert(testComparisons(d1, d2, true, false));
Expand Down Expand Up @@ -113,6 +113,14 @@ int main(int, char**) {
const std::deque<LessAndEqComp> d2(items2, items2 + 2);
assert(testComparisons(d1, d2, false, false));
}
return true;
}

int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@

#include "test_container_comparisons.h"

int main(int, char**) {
TEST_CONSTEXPR_CXX26 bool test() {
assert(test_sequence_container_spaceship<std::deque>());
// `std::deque` is not constexpr, so no `static_assert` test here.
return true;
}

int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ C make(int size, int start = 0) {
return c;
}

int main(int, char**) {
TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::deque<int> C;
C c = make<std::deque<int> >(10);
Expand Down Expand Up @@ -118,6 +118,14 @@ int main(int, char**) {
LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
}
#endif
return true;
}

int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "test_macros.h"
#include "min_allocator.h"

int main(int, char**) {
TEST_CONSTEXPR_CXX26 bool test() {
{
typedef std::deque<int> C;
C c;
Expand All @@ -46,6 +46,13 @@ int main(int, char**) {
LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
}
#endif
return true;
}

int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}
Loading
Loading