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 C4FD03858C2D for ; Mon, 12 Feb 2024 22:15:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4FD03858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4FD03858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707776155; cv=none; b=HXmxoiTvHJMpf1g4pWOLubjjTzkXn0DwsdGgFnI1duZfmF6+6czMxOkg5gaGg7PbxaAU/NeHDOx/t9DVV+JNF0PMhvqvPqJdHsgD9yDru8MF+Mefy35JJSrDei5CyJheJgRtwaFh9F9hg07aJZlOLOT97uTmZrwcgn6YZSF+vBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707776155; c=relaxed/simple; bh=YMkkWCCFEduCQSlPtq85NGru0zyMkc27iqIJ/4J9QZs=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=LDi7xclEKMUzhtcdzByqzcd6GCdCiLDhkeMnY53AoZLuTva+5AV8pFNrwIPYX23/MtBdhSeP3JP8bKP+0HcyZkYsGvJK2BqtcvgqRlSU60ipBD/3mvAshQvggr8WEsTxFixPPq5RQSw1+rS+hmXDiILgPVQ+B0OYSnlM03yfYPU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707776144; 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=A8eyZ+06pUHQ3SWKS3IoEShL4+rngOAv1oRy5XPhrKk=; b=D11whuvs1wK4YuNoHizvo4OsAsX4R3FG6+lIfn3HDjdLvWhzM44DO196iIPL53ccSmLQa8 IAilDb/F4onqyTzAgzh8mov5AnBJ1r+fzEQHGnRlgur55gUdTLSGjj5YoFkFnuB89RInRi HyZNOyC/Qa628htaZE510VAFqj7NQwI= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407-2pOBOEmMN5KjVDlG9fmztw-1; Mon, 12 Feb 2024 17:15:43 -0500 X-MC-Unique: 2pOBOEmMN5KjVDlG9fmztw-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-42c0d7c970eso2591731cf.0 for ; Mon, 12 Feb 2024 14:15:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707776142; x=1708380942; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A8eyZ+06pUHQ3SWKS3IoEShL4+rngOAv1oRy5XPhrKk=; b=ana1rkyg2yRVE/KoFKWPa5EjFf63ZGPHZe8/txdKpywgN/42FRQZ9apqo/xkVjKwMH AhFV7Wz4w0accXKW8oPLuV11kaQHIeXAdkoKfa0mUrCw7yNgW07aT/6mQzDrqSHZgtxQ rryted8gZrJ1czxu4/utY0mdH/7f6bIL008z7ujtPGe+Ex7nEP5oGNttmdkDOqI2Xc6B oCPkdNa2gvVWxxpd37YawKOttu//x88TwzZGXjwde54tOW9SLV3DAT/F2E//lGqDxwr7 3yHKPzZmF2udFUKftv1L6G3Cr1bz7m2QaR2ooIFjjR8bm/7VNjhzy4fGLaSi2HLlTQxO iK+g== X-Forwarded-Encrypted: i=1; AJvYcCV8P6FhaB5rxsfjKBFctKWbbEFZH+aiE7uleZz/eUi1uBDKxfbLytiFbD6JUgxTp73Yd3nrnf9rPTwLIrI/KXICOrJ9cVo= X-Gm-Message-State: AOJu0YzDgFLgFvhj9hmrEGbASUPEHuVNaAcqt9r7phutYxyyrUoNwkg+ f5/WGH7Wpg1wwtx+txMhtAH6jBFcO+wbt114kZ4Yjojh1nlyoCJdAFcgOgFunNF2xdjztXpywVo V/2bbMr/I5n3nNgZN+ZCnQiowJbVz5hPORyyoPAbJhbBc4dpl2rBZ X-Received: by 2002:a05:622a:181b:b0:42c:7641:6d62 with SMTP id t27-20020a05622a181b00b0042c76416d62mr5013520qtc.12.1707776142588; Mon, 12 Feb 2024 14:15:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyMOPscRB8j8A+PwOP8CGNUALeMBU/Rmnty8W9PX06JNNpkz/IiDPzmWMf0Cz8C2L3UnGbNA== X-Received: by 2002:a05:622a:181b:b0:42c:7641:6d62 with SMTP id t27-20020a05622a181b00b0042c76416d62mr5013508qtc.12.1707776142308; Mon, 12 Feb 2024 14:15:42 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXI4D/rcvJVP2f8M0CBnMlLxlFwPCyskmtIONqFpBO++qeYPhyJQR95X7a6PxrRS+4f5rEZoGRBOrsG3zi367FmUOfuf4U= Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id od9-20020a0562142f0900b0068c440bc7d0sm595750qvb.105.2024.02.12.14.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 14:15:41 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 12 Feb 2024 17:15:41 -0500 (EST) To: Paul Keir cc: "gcc-patches@gcc.gnu.org" , "libstdc++@gcc.gnu.org" Subject: Re: [PATCH] libstdc++: Fix constexpr basic_string union member [PR113294] In-Reply-To: Message-ID: <9393d5e5-4227-f8d1-1356-31d81da0287d@idea> References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.4 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,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 Mon, 12 Feb 2024, Paul Keir wrote: > A call to `basic_string::clear()` in the std::string move assignment operator leads to a constexpr error from an access of inactive union member `_M_local_buf` in the added test (`test_move()`). Changing `__str._M_local_buf` to `__str._M_use_local_data()` in `operator=(basic_string&& __str)` fixes this. > > Running `make check RUNTESTFLAGS="conformance.exp=21_strings/basic_string/*"` on x86_64-pc-linux-gnu gave unchanged summary results (# of expected passes 570 # of expected failures 4 # of unsupported tests 4). > > I don't have write access. > > Signed-off-by: Paul Keir LGTM! A ChangeLog entry is missing from the commit message, so here's one that we can use for this commit: PR libstdc++/113294 libstdc++-v3/ChangeLog: * include/bits/basic_string.h (basic_string::operator=): Use _M_use_local_data() instead of _M_local_buf on the moved-from string. * testsuite/21_strings/basic_string/modifiers/constexpr.cc (test_move): New test. > > diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h > index 43efc99bea9..8a695a494ef 100644 > --- a/libstdc++-v3/include/bits/basic_string.h > +++ b/libstdc++-v3/include/bits/basic_string.h > @@ -909,7 +909,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 > __str._M_capacity(__capacity); > } > else > - __str._M_data(__str._M_local_buf); > + __str._M_data(__str._M_use_local_data()); > } > else // Need to do a deep copy > assign(__str); > diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc > index 0e28a6d4487..ad7548f3236 100644 > --- a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc > +++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc > @@ -50,3 +50,16 @@ test_erasure() > } > > static_assert( test_erasure() ); > + > +constexpr bool > +test_move() > +{ > + std::string s1; > + std::string s2 = "1234567890123456"; // 16 chars: more than _S_local_capacity > + s1 = std::move(s2); > + VERIFY( s1 == "1234567890123456" ); > + > + return true; > +} > + > +static_assert( test_move() ); > -- > > > Please consider the environment and think before you print. > > The University of the West of Scotland is a registered Scottish charity. Charity number SC002520. > > This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. > > Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the University of the West of Scotland. > > As a public body, the University of the West of Scotland may be required to make available emails as well as other written forms of information as a result of a request made under the Freedom of Information (Scotland) Act 2002. > >