From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 6E7EF3858D39; Sat, 12 Nov 2022 00:41:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E7EF3858D39 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-pg1-x530.google.com with SMTP id b62so5647053pgc.0; Fri, 11 Nov 2022 16:41:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/GfHR692nH+1am38viH73if2i1brMD+I4/TDdmj0iBo=; b=jYSe7YmYb0rO7T9r+FWSM9IsjL8Qo40xOgsBr0NE/ApegV+SKOR+tMkX4cr4mUPgTq UA0NdHk0Ofn+ayDDSPbukUrQXnl0B4PXrwdEL4H90JbmnpFXXQEN+oT9Yj5JVzMRfIS1 qiw8KUtAyN55ckUqdH69Jsg0lccI56oXKtwiIKHTr0pHZE8Nh4PY1jYGYUrAPi+KKy/+ a3jJnKdyZR9oEonOKW6jlIcnkyO2ESUeCwN6jigb0R71tDU+cqEL2HARhFA4LjTfgz4S 7rO2CRG2xqSzmmGtPEWH7xJhsaWmZiPOMtPExjLCZW0cgqmhTogNeEZCXI5B1BNrqI0H wqaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/GfHR692nH+1am38viH73if2i1brMD+I4/TDdmj0iBo=; b=ZrCAk5gV+ddNda36QQI2fJizeCIkQvrtQOijZYE6xXSqMn2V+4Ww1ktVbnA+uFXLGh +uJd/HZwIJ8eYxI6DQnGQpF45PpgYeLaJtPJbzkKceYhl4Nd2391ntqgiUHNBWpM2+rQ uPnb/c8nvDrj/bV+udl6GYwlAU6Eqz70sZ01+cxc4o2P5iDOE5UNIIM+hzMfqbDzJ6Hv Dd/C2DcIRXaHGvJbbyuQU1fPYyEqbhRB0C2poZfTJJTrruHm42Wgp/3nFAAbijffiHku 8y4wSbZX3S5suQV+xpk/8YiXAUc/waMEpxQeigNqXtuGAubdwtLbKsPuxcRPRRZtGJAI tR5g== X-Gm-Message-State: ANoB5plg72JyutNMJGqAXqW3rP1S3krpMdsFK9qy+NcsIYoJvWUlRk/V UI1NskPQqJbJCbQPky3KwlA= X-Google-Smtp-Source: AA0mqf4ncPzc364c+UZifVmQ82Y4heY0Nki4Nir3YhRgMdevmwP/oZ3vhV1BBBb36W9r4gphOncEiQ== X-Received: by 2002:a63:4f1c:0:b0:470:2ecd:333e with SMTP id d28-20020a634f1c000000b004702ecd333emr3669355pgb.596.1668213692275; Fri, 11 Nov 2022 16:41:32 -0800 (PST) Received: from Thaum.localdomain (14-200-56-152.tpgi.com.au. [14.200.56.152]) by smtp.gmail.com with ESMTPSA id d11-20020a170902cecb00b00186b6a04636sm2306371plg.255.2022.11.11.16.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 16:41:31 -0800 (PST) Date: Sat, 12 Nov 2022 11:41:28 +1100 From: Nathaniel Shead To: Jonathan Wakely Cc: Patrick Palka , libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Set active union member in constexpr std::string [PR103295] Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: Thanks for that. I'll keep your comments in mind for the future. On Fri, Nov 11, 2022 at 05:59:33PM +0000, Jonathan Wakely wrote: > 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. >