From patchwork Fri Nov 11 11:23:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 18683 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp682349wru; Fri, 11 Nov 2022 03:24:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4nMV3QTUB6UQipnBVNdXNvkVAY/jFjoSl7K/Hjxi9zU1BV6Oe9KvGmzsqHft3r4sB7K2GD X-Received: by 2002:a17:906:2a1b:b0:7ae:4a7f:3280 with SMTP id j27-20020a1709062a1b00b007ae4a7f3280mr1521741eje.265.1668165872519; Fri, 11 Nov 2022 03:24:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668165872; cv=none; d=google.com; s=arc-20160816; b=WlWj4Y9vXHT94sMOKF2NxonlKa/CZ309RaeYKpL1RoaVv/qDSG7cvjPIR2oahOrh+s LL1r6CKaKPy0g2iFc4ElfOJUmyTqgTeQnJG2xKba+GoDcVY/9N0hXp8jdWizlQVDirAM 5K1IfI0aTqnr/5Cd4Hrff5U7Ed28JlQf/KWORtg0x9w+u1UjmSgmnx8cntAwPVGjzmPn bXxjAxP9IDkNupzVrlUDTlpaZeR71FEZn7vqdJPPiOodK9dwYmv0D2MoCbEuDWSiXa7A /cOVZ78pvrwTgOcikogk30G+V+EWSz+s0LQdywvKJlAxmUoCk/C4LaMMuwHxMo+mcF4S DRnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=opUASr+f6VupgUkRrCVXl50fdmCAQvDI5M39xjIvroc=; b=wWTia8KHhG4HDre17OTBD2dxaP64XaL0/trENRnm3gKeABhoPVZdUEzmv6EKFisf/s HqOl0FTew4hG8+p4V6iulXsTxZCrzyJoyEOrVqxNcJgR/7lGXleaBlPAtMj+fPsAttj9 UVIleeRCeF8DrrsBzN0SXM4jxvzCAB4H17+eWiIDE8EqHT/OJ2w/tTCIt0uu7YX51e7m ldgDO2RSQqNYROqp3ZAL6cCQUuInYlWTJ2669SKyzdytgxeVtTDvtKcKj7gkon/Zjv/3 PaNKTaVjZzNWxLD0FjjuAagB6w//uWu52bX58DxDvYw5fOHDlvfVR7kbXoKRdLDYnrZy Wjeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pQcip6p7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hb38-20020a170907162600b007ae670adb82si1900556ejc.902.2022.11.11.03.24.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 03:24:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pQcip6p7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 720FE384F036 for ; Fri, 11 Nov 2022 11:24:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 720FE384F036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668165862; bh=opUASr+f6VupgUkRrCVXl50fdmCAQvDI5M39xjIvroc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pQcip6p71v266d8Y+KAHsM/TKNYGnzEYbld188y/OkOK6PBVdc7+WYZcQW9n9iSs4 CkR2HwAufuK5YQt64i1nyjeVuQFGiM2iPRJbRYAyQmJhKbPRYb9tl5veY9p7nSArk/ HW/R5qZ0YDqdH7XdLjdNf34U17IYJ1yUoi+slDTA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 Received: by mail-pf1-x42f.google.com with SMTP id 140so3182137pfz.6; Fri, 11 Nov 2022 03:23:37 -0800 (PST) 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-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 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-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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Nathaniel Shead via Gcc-patches From: Nathaniel Shead Reply-To: Nathaniel Shead Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749198697677187214?= X-GMAIL-MSGID: =?utf-8?q?1749198697677187214?= 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(); }