diff --git a/libcxx/include/deque b/libcxx/include/deque --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -1079,6 +1079,14 @@ const void* __new_beg = __front ? __new_edge : __old_edge; const void* __new_end = __front ? __old_edge : __new_edge; + _LIBCPP_ASSERT(__old_beg <= __old_end, "invalide old range"); + _LIBCPP_ASSERT(__mem_beg <= __old_beg, "invalide old range"); + _LIBCPP_ASSERT(__old_end <= __mem_end, "invalide old range"); + + _LIBCPP_ASSERT(__new_beg <= __new_end, "invalide new range"); // This one fails + _LIBCPP_ASSERT(__mem_beg <= __new_beg, "invalide new range"); + _LIBCPP_ASSERT(__new_end <= __mem_end, "invalide new range"); + __annotate_double_ended_contiguous_container(__mem_beg, __mem_end, __old_beg, __old_end, __new_beg, __new_end); } } diff --git a/libcxx/test/libcxx/containers/sequences/deque/annotate.begin.end.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/annotate.begin.end.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/containers/sequences/deque/annotate.begin.end.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// Regression test to error in deque::__annotate_from_to in deque. + +// REQUIRES: has-unix-headers +// UNSUPPORTED: c++03 +// XFAIL: availability-verbose_abort-missing +// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_ASSERTIONS=1 + +#include + +#include "check_assertion.h" + +int main(int, char**) { + std::deque test; + char buff[100000]; + test.insert(test.end(), buff, buff + 64000); + + for (int i = 0; i < 1100; i += 1) { + test.insert(test.end(), buff, buff + 320); + test.erase(test.begin(), test.begin() + 320); + } + + test.insert(test.end(), buff, buff + 32000); + + return 0; +}