forked from OSchip/llvm-project
[libc++] Fix __wrap_iter copy-assignment in constexpr contexts
Fixes https://github.com/llvm/llvm-project/issues/52902 In debug mode during constant evaluation the iterator was never assigend. There seem to be no other instances of this bug. Reviewed By: Quuxplusone, Mordante, #libc, ldionne Spies: ldionne, libcxx-commits Differential Revision: https://reviews.llvm.org/D116346
This commit is contained in:
parent
fb7bea0a5a
commit
c9dbf0f2a1
|
@ -69,9 +69,10 @@ public:
|
|||
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
__wrap_iter& operator=(const __wrap_iter& __x)
|
||||
{
|
||||
if (this != _VSTD::addressof(__x) && !__libcpp_is_constant_evaluated())
|
||||
if (this != _VSTD::addressof(__x))
|
||||
{
|
||||
__get_db()->__iterator_copy(this, _VSTD::addressof(__x));
|
||||
if (!__libcpp_is_constant_evaluated())
|
||||
__get_db()->__iterator_copy(this, _VSTD::addressof(__x));
|
||||
__i = __x.__i;
|
||||
}
|
||||
return *this;
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
#include "test_macros.h"
|
||||
|
||||
template<class C>
|
||||
void test()
|
||||
TEST_CONSTEXPR_CXX20 void test()
|
||||
{
|
||||
{ // N3644 testing
|
||||
typename C::iterator ii1{}, ii2{};
|
||||
typename C::iterator ii4 = ii1;
|
||||
typename C::const_iterator cii{};
|
||||
|
||||
assert ( ii1 == ii2 );
|
||||
assert ( ii1 == ii4 );
|
||||
|
||||
|
@ -49,10 +50,17 @@ void test()
|
|||
assert (cii - ii1 == 0);
|
||||
assert (ii1 - cii == 0);
|
||||
}
|
||||
{
|
||||
C a;
|
||||
typename C::iterator i1 = a.begin();
|
||||
typename C::iterator i2;
|
||||
assert ( i1 != i2 );
|
||||
i2 = i1;
|
||||
assert ( i1 == i2 );
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
test<std::string>();
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
test<std::wstring>();
|
||||
|
@ -65,5 +73,14 @@ int main(int, char**)
|
|||
test<std::u16string>();
|
||||
test<std::u32string>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test();
|
||||
#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
|
||||
static_assert(test());
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue