From: Nathaniel Shead Date: Fri, 11 Nov 2022 11:23:31 +0000 (+1100) Subject: libstdc++: Set active union member in constexpr std::string [PR103295] X-Git-Tag: basepoints/gcc-14~3297 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52672be7d328df50f9a05ce3ab44ebcae50fee1b;p=thirdparty%2Fgcc.git libstdc++: Set active union member in constexpr std::string [PR103295] Clang still complains about using std::string in constexpr contexts due to the changes made in commit 98a0d72a. This patch ensures that we set the active member of the union as according to [class.union.general] p6. libstdc++-v3/ChangeLog: PR libstdc++/103295 * include/bits/basic_string.h (_M_use_local_data): Set active member to _M_local_buf. Signed-off-by: Nathaniel Shead --- diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 9c2b57f5a1d7..109915653af0 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -352,8 +352,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { #if __cpp_lib_is_constant_evaluated if (std::is_constant_evaluated()) - for (_CharT& __c : _M_local_buf) - __c = _CharT(); + for (size_type __i = 0; __i <= _S_local_capacity; ++__i) + _M_local_buf[__i] = _CharT(); #endif return _M_local_data(); }