From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 618233858C2B for ; Fri, 11 Nov 2022 17:59:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 618233858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668189587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7O06oGGVa4552B25O6a1JD9SbKmlJTkgPsL6+y+fTmw=; b=Au6l1Dw+gbsWkXx9hGAuS/idmpKSd5J8lJdi4G7NsJbxa+V4vNyzyXJZwr8Www2B+IT50c K7oDC3bbQqb1HZ1WuPiM5afIDcKsycM7YylpDMldRHJWqGT5qG0s8vGh4OWnoXTD5ZJv3x A6Qvk6lyRNVB9l6V7qcIIAUyDNRiwzo= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-231-hRV1SxuAMGGq-dVmLcWMeQ-1; Fri, 11 Nov 2022 12:59:45 -0500 X-MC-Unique: hRV1SxuAMGGq-dVmLcWMeQ-1 Received: by mail-ej1-f69.google.com with SMTP id sh31-20020a1709076e9f00b007ae32b7eb51so3383553ejc.9 for ; Fri, 11 Nov 2022 09:59:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7O06oGGVa4552B25O6a1JD9SbKmlJTkgPsL6+y+fTmw=; b=6EWDnlMkyhwrMfQty/UCMPwAROhOS94u0PR4XyfuwEGTtBM5R/gVwqliOGWqpedRG8 sR7XnRQWKYNIAdCHLzsNFjS1BwEtEAwLtzoZd7+pO6D1RZcbwpiHjNmTZstnUhcsyddV H2JMd2WoyKwtI74npEggQE47a5GyEUPLEUtyf8kKQ2TFDuU/SLfhLORYUXfKmyc9A35n 3RA3+i3SHafJzASPQuPX4YRzE8gQ2XW56i/rS04Uj475NmhbglG6P+r8HTuzafab8T5g SfWe2LP+r0FUJvM9tZdxxTJu7qvmOEM6AdWKLbIdUwHq8fNs7M+CPwfFNMsbjMSwJWm6 dt9A== X-Gm-Message-State: ANoB5pl3eDgUmktmF9XNiPyXePf7Ai+D1hLG9iByyUV6Y3dZPCjhq69w 9tmMgj/uRpnk89zGpg/xGVWfSMun3LG8V4dqm920IbVcqDq72F3ZBnLuCQPyJAUtZ2km1Ue0wvz viFnKUeKkI9bJ0RkQT4Ux0FJZ3yFAbjivoA== X-Received: by 2002:a50:eb04:0:b0:462:67f9:7469 with SMTP id y4-20020a50eb04000000b0046267f97469mr2623119edp.17.1668189584579; Fri, 11 Nov 2022 09:59:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf7dmoULE5vtJDzeniDnXb8Dv47bLXiij0r2PKgvJOmqmRsReDMRu8oaPGDmUtEgIfzKDiRVsBY5S0c1F6SP3L8= X-Received: by 2002:a50:eb04:0:b0:462:67f9:7469 with SMTP id y4-20020a50eb04000000b0046267f97469mr2623103edp.17.1668189584403; Fri, 11 Nov 2022 09:59:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 11 Nov 2022 17:59:33 +0000 Message-ID: Subject: Re: [PATCH] libstdc++: Set active union member in constexpr std::string [PR103295] To: Patrick Palka Cc: Nathaniel Shead , libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: On Fri, 11 Nov 2022 at 17:55, Patrick Palka wrote: > > On Fri, 11 Nov 2022, Jonathan Wakely via Libstdc++ wrote: > > > On Fri, 11 Nov 2022 at 11:23, Nathaniel Shead via Libstdc++ > > wrote: > > > > > > 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! > > > > Thanks for the patch, I'll get this committed today. > > > > The only thing I had to fix was the indentation in the commit log. The > > second line of the ChangeLog should be aligned with the * not the text > > following it (so indented by a single tab). > > > > > > > > > > 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(); > > Just a minor nit, but we should probably uglify i to __i here. Good catch, thanks. Fixed and pushed.