https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107087
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> --- This prevents the warning: --- a/libstdc++-v3/include/bits/cow_string.h +++ b/libstdc++-v3/include/bits/cow_string.h @@ -911,13 +911,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// null-termination. size_type size() const _GLIBCXX_NOEXCEPT - { return _M_rep()->_M_length; } + { +#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__ + if (_M_rep() == &_S_empty_rep() && _M_rep()->_M_length != 0) + __builtin_unreachable(); +#endif + return _M_rep()->_M_length; + } /// Returns the number of characters in the string, not including any /// null-termination. size_type length() const _GLIBCXX_NOEXCEPT - { return _M_rep()->_M_length; } + { +#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__ + if (_M_rep() == &_S_empty_rep() && _M_rep()->_M_length != 0) + __builtin_unreachable(); +#endif + return _M_rep()->_M_length; + } /// Returns the size() of the largest possible %string. size_type