From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 7FF733858D35; Fri, 11 Nov 2022 11:23:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7FF733858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42f.google.com with SMTP id 140so3182137pfz.6; Fri, 11 Nov 2022 03:23:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=opUASr+f6VupgUkRrCVXl50fdmCAQvDI5M39xjIvroc=; b=cBULYbUO1jWu/iutoSBoM+qMeg59qXLxfM/2vm+1+pKvLq7ta4NCUlNQyMHFsfDRtQ 4RcFG9Wm5iS/ofsw/ADxah8usnTMkjP4vHksvNcgjWse1RJhDPs3VQ4KRxhCu8l/jrHG 6nJJtetkFMupoTloWM5sIrIp558ouVRSiKnIBRyDJ35WYIesmnJf1ysLLR41FSURIcC5 i43oBqNBiAEy0tkMoyEdNP8fkkoL3xhmAM6Tq7gKc2qxNvxqYVB4ysFH/biUtghKDs6u syaIhmddbthHRHfkB3APYwwkowuCvxcjb8BSdCF7nL1kgKMyAb8nGhBAldL+AgqWImEQ 3dAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=opUASr+f6VupgUkRrCVXl50fdmCAQvDI5M39xjIvroc=; b=G7ryhWjDFNwQZJLGAeaxlL40utjMnHmdh0ycUU3lE1wnTcahBnaj6l4OAWqx9e5L5J bru9wNwHNpyDGABc1xVwiovg3kQN6q6OztIVTG7iBPErlanTk04u2/pVtdQMTE6U7KKM 64yS9qRtW16CJYy99ZD3/dHBNn8e5sGCvZ8nIWkZVVWLK425kYTMqUxmiEvEbzO1wDN/ WuO8VJo4MCNHvMo6XGtCn3qJUtNf0uAlGxXiLfPjqGsb0oqvmbvLrZYaX/SzTeoAAUq1 J4DtTi9Etnov2WDHFt1t8D+4IMunTLG7b2KGZqpNNxVYX9rPNvFcOM3uC2D5WOtUEp39 XF1A== X-Gm-Message-State: ANoB5pncCkEDKQTwHO/Woq2EoparJQxn0tF7neDz9x+qZx+re0dugrCW FlnXkt80qCtQwBG9sWhWwWLFoYugpBj89g== X-Google-Smtp-Source: AA0mqf6vxfk2m5fdI063LjADUBgfb8rS4buNkFGCO0vFg0o+4CjdSeacHd4mmR4/g3TJHTfjRZ2vtg== X-Received: by 2002:a63:f91e:0:b0:464:bb6a:50de with SMTP id h30-20020a63f91e000000b00464bb6a50demr1170802pgi.502.1668165816166; Fri, 11 Nov 2022 03:23:36 -0800 (PST) Received: from Thaum.localdomain (14-200-56-152.tpgi.com.au. [14.200.56.152]) by smtp.gmail.com with ESMTPSA id n13-20020a170902e54d00b0017f73dc1549sm1454087plf.263.2022.11.11.03.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 03:23:35 -0800 (PST) Date: Fri, 11 Nov 2022 22:23:31 +1100 From: Nathaniel Shead To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Set active union member in constexpr std::string [PR103295] Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, Below is a patch to fix std::string in constexpr contexts on Clang. This was originally fixed in the commits attached to PR103295, but a later commit 98a0d72a seems to have mistakenly undone this. Tested on x86_64-linux. Verified using clang-14 and clang-15 that the fix works. I haven't added anything to the test suite, since this issue is only detected by clang. This is my first time contributing, so please let me know if I've done anything wrong or missed something. Thanks! Nathaniel -- >8 -- 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 --- 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..2790fd49b05 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(); } -- 2.34.1