From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 60CC83858D20; Fri, 11 Nov 2022 17:59:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60CC83858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668189552; bh=hWApI0zCKoUz/xlWUB7t84tVsRi7bjwr4kLe694/pNU=; h=From:To:Subject:Date:From; b=oipC1AbLl4oT6j94kBqkAzQjfGxImMzXwIyhKxF352EydpHqtLbNDIisI/aOyu4X5 myg0a6g7/ddhlc/qu8YjFqAHTORKE6CX9SzkctxAKomWy0IoR0/fqcpka1azbHLv3q XsteZT47ZtsYV0XLrT82PysDsYdLUIN8h32erfJg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3910] libstdc++: Set active union member in constexpr std::string [PR103295] X-Act-Checkin: gcc X-Git-Author: Nathaniel Shead X-Git-Refname: refs/heads/master X-Git-Oldrev: b331bf303bdc1edead41e2b3d11d1a7804b433cf X-Git-Newrev: 52672be7d328df50f9a05ce3ab44ebcae50fee1b Message-Id: <20221111175912.60CC83858D20@sourceware.org> Date: Fri, 11 Nov 2022 17:59:12 +0000 (GMT) List-Id: https://gcc.gnu.org/g:52672be7d328df50f9a05ce3ab44ebcae50fee1b commit r13-3910-g52672be7d328df50f9a05ce3ab44ebcae50fee1b Author: Nathaniel Shead Date: Fri Nov 11 22:23:31 2022 +1100 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: --- libstdc++-v3/include/bits/basic_string.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 9c2b57f5a1d..109915653af 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(); }