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.133.124]) by sourceware.org (Postfix) with ESMTPS id 51E0E3857360 for ; Thu, 16 Jun 2022 19:21:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 51E0E3857360 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-kmAZ3sQqPSGGQLJ5J4uISw-1; Thu, 16 Jun 2022 15:21:12 -0400 X-MC-Unique: kmAZ3sQqPSGGQLJ5J4uISw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 39DD7811E75; Thu, 16 Jun 2022 19:21:12 +0000 (UTC) Received: from localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03B78C53360; Thu, 16 Jun 2022 19:21:11 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Support constexpr global std::string for size < 15 [PR105995] Date: Thu, 16 Jun 2022 20:21:11 +0100 Message-Id: <20220616192111.1199662-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URI_HEX 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: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jun 2022 19:21:15 -0000 Tested x86_64-linux, pushed to trunk. -- >8 -- I don't think this is required by the standard, but it's easy to support. libstdc++-v3/ChangeLog: PR libstdc++/105995 * include/bits/basic_string.h (_M_use_local_data): Initialize the entire SSO buffer. * testsuite/21_strings/basic_string/cons/char/105995.cc: New test. --- libstdc++-v3/include/bits/basic_string.h | 3 ++- .../21_strings/basic_string/cons/char/105995.cc | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/cons/char/105995.cc diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 57247e306dc..b04fba95678 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -352,7 +352,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { #if __cpp_lib_is_constant_evaluated if (std::is_constant_evaluated()) - _M_local_buf[0] = _CharT(); + for (_CharT& __c : _M_local_buf) + __c = _CharT(); #endif return _M_local_data(); } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/105995.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/105995.cc new file mode 100644 index 00000000000..aa8bcba3dca --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/105995.cc @@ -0,0 +1,9 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } +// { dg-require-effective-target cxx11_abi } + +// PR libstdc++/105995 +// Not required by the standard, but supported for QoI. +constexpr std::string pr105995_empty; +constexpr std::string pr105995_partial = "0"; +constexpr std::string pr105995_full = "0123456789abcde"; -- 2.34.3