diff --git a/libcxx/include/__debug b/libcxx/include/__debug --- a/libcxx/include/__debug +++ b/libcxx/include/__debug @@ -34,7 +34,7 @@ # define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) # define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) #elif _LIBCPP_DEBUG_LEVEL == 2 -# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m) +# define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(__libcpp_is_constant_evaluated() || (x), m) # define _LIBCPP_ASSERT_IMPL(x, m) ((x) ? (void)0 : _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) #else # error _LIBCPP_DEBUG_LEVEL must be one of 0, 1, 2 diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -826,9 +826,10 @@ basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); -# if _LIBCPP_DEBUG_LEVEL == 2 +#if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); -# endif +#endif } template ::value, nullptr_t> > @@ -1785,6 +1786,7 @@ basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() { #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__invalidate_all(this); #endif } @@ -1795,6 +1797,7 @@ basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) { #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) { __c_node* __c = __get_db()->__find_c_and_lock(this); if (__c) { @@ -1812,8 +1815,9 @@ } __get_db()->unlock(); } + } #else - (void)__pos; + (void)__pos; #endif // _LIBCPP_DEBUG_LEVEL == 2 } @@ -1824,9 +1828,10 @@ : __r_(__default_init_tag(), __default_init_tag()) { #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif - __zero(); + __zero(); } template @@ -1840,9 +1845,10 @@ : __r_(__default_init_tag(), __a) { #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif - __zero(); + __zero(); } template @@ -1899,9 +1905,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) : __r_(__default_init_tag(), __a) { - _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); - __init(__s, traits_type::length(__s)); + _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); + __init(__s, traits_type::length(__s)); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -1911,9 +1918,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) : __r_(__default_init_tag(), __default_init_tag()) { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); - __init(__s, __n); + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); + __init(__s, __n); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -1923,9 +1931,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) : __r_(__default_init_tag(), __a) { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); - __init(__s, __n); + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); + __init(__s, __n); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -1941,6 +1950,7 @@ __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -1956,6 +1966,7 @@ __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -1991,11 +2002,13 @@ #endif : __r_(_VSTD::move(__str.__r_)) { - __str.__zero(); + __str.__zero(); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) { __get_db()->__insert_c(this); if (__is_long()) __get_db()->swap(this, &__str); + } #endif } @@ -2012,9 +2025,11 @@ __str.__zero(); } #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) { __get_db()->__insert_c(this); if (__is_long()) __get_db()->swap(this, &__str); + } #endif } @@ -2049,8 +2064,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) : __r_(__default_init_tag(), __default_init_tag()) { - __init(__n, __c); + __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2060,8 +2076,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) : __r_(__default_init_tag(), __a) { - __init(__n, __c); + __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2077,6 +2094,7 @@ this->__throw_out_of_range(); __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2092,6 +2110,7 @@ this->__throw_out_of_range(); __init(__str.data() + __pos, __str_sz - __pos); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2106,6 +2125,7 @@ __self_view __sv = __sv0.substr(__pos, __n); __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2118,6 +2138,7 @@ __self_view __sv = __t; __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2130,6 +2151,7 @@ __self_view __sv = __t; __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2210,8 +2232,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) : __r_(__default_init_tag(), __default_init_tag()) { - __init(__first, __last); + __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2223,8 +2246,9 @@ const allocator_type& __a) : __r_(__default_init_tag(), __a) { - __init(__first, __last); + __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2237,8 +2261,9 @@ initializer_list<_CharT> __il) : __r_(__default_init_tag(), __default_init_tag()) { - __init(__il.begin(), __il.end()); + __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2250,8 +2275,9 @@ initializer_list<_CharT> __il, const _Allocator& __a) : __r_(__default_init_tag(), __a) { - __init(__il.begin(), __il.end()); + __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__insert_c(this); #endif } @@ -2262,10 +2288,11 @@ basic_string<_CharT, _Traits, _Allocator>::~basic_string() { #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) __get_db()->__erase_c(this); #endif - if (__is_long()) - __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); + if (__is_long()) + __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); } template @@ -2960,6 +2987,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::insert(iterator, n, value) called with an iterator not" " referring to this string"); @@ -3467,18 +3495,20 @@ #endif { #if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) { if (!__is_long()) __get_db()->__invalidate_all(this); if (!__str.__is_long()) __get_db()->__invalidate_all(&__str); __get_db()->swap(this, &__str); + } #endif - _LIBCPP_ASSERT( - __alloc_traits::propagate_on_container_swap::value || - __alloc_traits::is_always_equal::value || - __alloc() == __str.__alloc(), "swapping non-equal allocators"); - _VSTD::swap(__r_.first(), __str.__r_.first()); - _VSTD::__swap_allocator(__alloc(), __str.__alloc()); + _LIBCPP_ASSERT( + __alloc_traits::propagate_on_container_swap::value || + __alloc_traits::is_always_equal::value || + __alloc() == __str.__alloc(), "swapping non-equal allocators"); + _VSTD::swap(__r_.first(), __str.__r_.first()); + _VSTD::__swap_allocator(__alloc(), __str.__alloc()); } // find