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/bit b/libcxx/include/bit --- a/libcxx/include/bit +++ b/libcxx/include/bit @@ -308,7 +308,7 @@ { if (__t < 2) return 1; const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u)); - _LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); + _LIBCPP_ASSERT(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil"); if constexpr (sizeof(_Tp) >= sizeof(unsigned)) return _Tp{1} << __n; 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 - __get_db()->__insert_c(this); -# endif +#if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); +#endif } template ::value, nullptr_t> > @@ -1785,7 +1786,8 @@ basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__invalidate_all(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__invalidate_all(this); #endif } @@ -1795,22 +1797,24 @@ basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) { #if _LIBCPP_DEBUG_LEVEL == 2 - __c_node* __c = __get_db()->__find_c_and_lock(this); - if (__c) - { - const_pointer __new_last = __get_pointer() + __pos; - for (__i_node** __p = __c->end_; __p != __c->beg_; ) + if (!__libcpp_is_constant_evaluated()) { + __c_node* __c = __get_db()->__find_c_and_lock(this); + if (__c) { - --__p; - const_iterator* __i = static_cast((*__p)->__i_); - if (__i->base() > __new_last) + const_pointer __new_last = __get_pointer() + __pos; + for (__i_node** __p = __c->end_; __p != __c->beg_; ) { - (*__p)->__c_ = nullptr; - if (--__c->end_ != __p) - _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + --__p; + const_iterator* __i = static_cast((*__p)->__i_); + if (__i->base() > __new_last) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } } + __get_db()->unlock(); } - __get_db()->unlock(); } #else (void)__pos; @@ -1824,7 +1828,8 @@ : __r_(__default_init_tag(), __default_init_tag()) { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif __zero(); } @@ -1840,7 +1845,8 @@ : __r_(__default_init_tag(), __a) { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif __zero(); } @@ -1902,7 +1908,8 @@ _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); __init(__s, traits_type::length(__s)); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1911,10 +1918,11 @@ 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 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1926,7 +1934,8 @@ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); __init(__s, __n); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1941,7 +1950,8 @@ __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1956,7 +1966,8 @@ __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -1993,9 +2004,11 @@ { __str.__zero(); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); - if (__is_long()) - __get_db()->swap(this, &__str); + 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 - __get_db()->__insert_c(this); - if (__is_long()) - __get_db()->swap(this, &__str); + if (!__libcpp_is_constant_evaluated()) { + __get_db()->__insert_c(this); + if (__is_long()) + __get_db()->swap(this, &__str); + } #endif } @@ -2051,7 +2066,8 @@ { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2062,7 +2078,8 @@ { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2077,7 +2094,8 @@ this->__throw_out_of_range(); __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2092,7 +2110,8 @@ this->__throw_out_of_range(); __init(__str.data() + __pos, __str_sz - __pos); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2106,7 +2125,8 @@ __self_view __sv = __sv0.substr(__pos, __n); __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2118,7 +2138,8 @@ __self_view __sv = __t; __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2130,7 +2151,8 @@ __self_view __sv = __t; __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2212,7 +2234,8 @@ { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2225,7 +2248,8 @@ { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2239,7 +2263,8 @@ { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2252,7 +2277,8 @@ { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__insert_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__insert_c(this); #endif } @@ -2262,7 +2288,8 @@ basic_string<_CharT, _Traits, _Allocator>::~basic_string() { #if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__erase_c(this); + if (!__libcpp_is_constant_evaluated()) + __get_db()->__erase_c(this); #endif if (__is_long()) __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); @@ -3467,11 +3494,13 @@ #endif { #if _LIBCPP_DEBUG_LEVEL == 2 - if (!__is_long()) - __get_db()->__invalidate_all(this); - if (!__str.__is_long()) - __get_db()->__invalidate_all(&__str); - __get_db()->swap(this, &__str); + 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 ||