From patchwork Tue Apr 28 22:49:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1278767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=F/T69lr5; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49BcJq27rbz9sSG for ; Wed, 29 Apr 2020 08:49:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 516063957061; Tue, 28 Apr 2020 22:49:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 516063957061 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588114150; bh=UKScsAmsChd5EMHwNfNsnzDSQ76AgEV15t4I/7pnK5g=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=F/T69lr5wrjPOyI38pgXHDlxJf/MQuUwKwTWt4Z8WzwdGZbSaSr3ydnSzY69F4SSj C+d9QsYgUYOSN+EMNlOodtdvtjryXoLtcsTcmHtazYEVG9yyH86f/aNhJUQGlkzUop C1ojeobD1B0OXFevJfMX0mO2Cee6Ve/jKJy2GTKM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id BAA2E3954C7A for ; Tue, 28 Apr 2020 22:49:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BAA2E3954C7A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-prDd2xmdOXqW2rvLkTNf3g-1; Tue, 28 Apr 2020 18:49:03 -0400 X-MC-Unique: prDd2xmdOXqW2rvLkTNf3g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07CAC8014D6; Tue, 28 Apr 2020 22:49:02 +0000 (UTC) Received: from localhost (unknown [10.33.37.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D99C60C18; Tue, 28 Apr 2020 22:49:01 +0000 (UTC) Date: Tue, 28 Apr 2020 23:49:00 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix regression in std::_Construct (PR 94831) Message-ID: <20200428224900.GA2910783@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-28.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" By trying to reuse the existing std::_Construct function as a wrapper for std::construct_at I introduced regressions, because changing std::_Construct to return non-void made it ill-formed for array types. The solution is to revert _Construct to its former state, and change allocator_traits::construct to explicitly call construct_at instead. This decouples all the existing callers of _Construct from the new construct_at requirements. PR libstdc++/94831 * include/bits/alloc_traits.h (_S_construct): Restore placement new-expression for C++11/14/17 and call std::construct_at directly for C++20. * include/bits/stl_construct.h (_Construct): Revert to non-constexpr function returning void. * testsuite/20_util/specialized_algorithms/ uninitialized_value_construct/94831.cc: New test. * testsuite/23_containers/vector/cons/94831.cc: New test. Tested powerpc64le-linux, committed to master. commit 162c40a4c127cc55d701bb8760e17708d0ca2fe0 Author: Jonathan Wakely Date: Tue Apr 28 23:26:21 2020 +0100 libstdc++: Fix regression in std::_Construct (PR 94831) By trying to reuse the existing std::_Construct function as a wrapper for std::construct_at I introduced regressions, because changing std::_Construct to return non-void made it ill-formed for array types. The solution is to revert _Construct to its former state, and change allocator_traits::construct to explicitly call construct_at instead. This decouples all the existing callers of _Construct from the new construct_at requirements. PR libstdc++/94831 * include/bits/alloc_traits.h (_S_construct): Restore placement new-expression for C++11/14/17 and call std::construct_at directly for C++20. * include/bits/stl_construct.h (_Construct): Revert to non-constexpr function returning void. * testsuite/20_util/specialized_algorithms/ uninitialized_value_construct/94831.cc: New test. * testsuite/23_containers/vector/cons/94831.cc: New test. diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index 061d353e3f0..6066f48d24c 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -253,7 +253,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _S_construct(_Alloc&, _Tp* __p, _Args&&... __args) noexcept(noexcept(::new((void*)__p) _Tp(std::forward<_Args>(__args)...))) - { std::_Construct(__p, std::forward<_Args>(__args)...); } + { +#if __cplusplus <= 201703L + ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); +#else + std::construct_at(__p, std::forward<_Args>(__args)...); +#endif + } template static _GLIBCXX14_CONSTEXPR auto diff --git a/libstdc++-v3/include/bits/stl_construct.h b/libstdc++-v3/include/bits/stl_construct.h index 5c9a84d9497..72a7cb4712c 100644 --- a/libstdc++-v3/include/bits/stl_construct.h +++ b/libstdc++-v3/include/bits/stl_construct.h @@ -65,9 +65,9 @@ * std::destroy_n, and the C++20 function std::construct_at. * It also provides std::_Construct, std::_Destroy,and std::_Destroy_n functions * which are defined in all standard modes and so can be used in C++98-14 code. - * The _Construct and _Destroy functions will dispatch to construct_at and - * destroy_at during constant evaluation, because calls to those functions are - * intercepted by the compiler to allow use in constant expressions. + * The _Destroy functions will dispatch to destroy_at during constant + * evaluation, because calls to that function are intercepted by the compiler + * to allow use in constant expressions. */ namespace std _GLIBCXX_VISIBILITY(default) @@ -104,23 +104,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ #if __cplusplus >= 201103L template - constexpr _Tp* + inline void _Construct(_Tp* __p, _Args&&... __args) - { -#if __cplusplus > 201703L - return std::construct_at(__p, std::forward<_Args>(__args)...); -#else - return ::new(static_cast(__p)) _Tp(std::forward<_Args>(__args)...); -#endif - } + { ::new(static_cast(__p)) _Tp(std::forward<_Args>(__args)...); } #else template - inline _T1* + inline void _Construct(_T1* __p, const _T2& __value) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 402. wrong new expression in [some_]allocator::construct - return ::new(static_cast(__p)) _T1(__value); + ::new(static_cast(__p)) _T1(__value); } #endif diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct/94831.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct/94831.cc new file mode 100644 index 00000000000..27506fae09f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct/94831.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include + +void +test01() +{ + // PR libstdc++/94831 + float i[2]; + std::uninitialized_value_construct(&i, &i + 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/94831.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/94831.cc new file mode 100644 index 00000000000..72dfcaae9af --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/94831.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++11 } } + +#include + +void +test01() +{ + // PR libstdc++/94831.cc + // We allow this in C++11 and later as a GNU extension. + // FIXME: make it ill-formed when __STRICT_ANSI__ is defined. + std::vector v(1u); +}