From patchwork Tue Sep 3 14:09:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1980071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ppu37oy3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WynZQ699yz1yfv for ; Wed, 4 Sep 2024 00:10:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B6F93386100D for ; Tue, 3 Sep 2024 14:10:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3FDBA385E45D for ; Tue, 3 Sep 2024 14:09:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FDBA385E45D 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 3FDBA385E45D 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=1725372580; cv=none; b=chcsWargA4kG1dhLERv0CzeE+wa/aimE8MQPdLQty6hHw6asZMOoSkzqZpKtuLzVkbrxuH+XnX0rCLahAfuq5XN5S4CU1sKmKhCh8gM+HwSJ3iIWM/MrIj2XZmAhMCd2iUdlualDEvEkNCszkfz6k0hKoGW1kfXJMEUkwU2QIhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725372580; c=relaxed/simple; bh=ZgrzdBz5lCZN+XjlI0epEPiAcM4mVBut/tAE3WDj15M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TyKJ85W5ylf9mRu0Wh1NRKqFHKlbafgYoHxdRcSq6UF5I/BgueBhnGIvq9mWrlbR5XXKo+xlz7P9DsHwWvyPinhAIwx3a9aDY6tLxtbLIj4UsYEHPn/omczmEPZsJgKuyAkMexbi8WwPme9IIra5TYll/uy4zh47QT1t+ox2kts= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725372579; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UIvX0mCh9tsslGPatjH7kN0DEsDWuThABWrWLTWi8Fc=; b=Ppu37oy3a6PhcJehyh2U+X9K+vM4UHlkCEh+j3pbzkhA3gk2qeFkAqeSWndBRuo+RDDpDT AzlPvqI2VEsVUsBtJg8EJgsF37uPyJnL9LCLuPo2+YK5zUVGVSUCDVZRi99ns3KnjaAMS7 FzFyfPNQAqG05ptCjPGDhI5c91GJmYc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-5goNyxDvML-GQ2sEZWOz5g-1; Tue, 03 Sep 2024 10:09:35 -0400 X-MC-Unique: 5goNyxDvML-GQ2sEZWOz5g-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B70BA1955D4F; Tue, 3 Sep 2024 14:09:33 +0000 (UTC) Received: from localhost (unknown [10.42.28.101]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2A4401955BE1; Tue, 3 Sep 2024 14:09:32 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Simplify std::any to fix -Wdeprecated-declarations warning Date: Tue, 3 Sep 2024 15:09:12 +0100 Message-ID: <20240903140931.2659102-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- We don't need to use std::aligned_storage in std::any. We just need a POD type of the right size. The void* union member already ensures the alignment will be correct. Avoiding std::aligned_storage means we don't need to suppress a -Wdeprecated-declarations warning. libstdc++-v3/ChangeLog: * include/experimental/any (experimental::any::_Storage): Use array of unsigned char instead of deprecated std::aligned_storage. * include/std/any (any::_Storage): Likewise. * testsuite/20_util/any/layout.cc: New test. --- libstdc++-v3/include/experimental/any | 2 +- libstdc++-v3/include/std/any | 2 +- libstdc++-v3/testsuite/20_util/any/layout.cc | 22 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/any/layout.cc diff --git a/libstdc++-v3/include/experimental/any b/libstdc++-v3/include/experimental/any index 27a7a146e53..3db30df5c75 100644 --- a/libstdc++-v3/include/experimental/any +++ b/libstdc++-v3/include/experimental/any @@ -102,7 +102,7 @@ inline namespace fundamentals_v1 _Storage& operator=(const _Storage&) = delete; void* _M_ptr; - aligned_storage::type _M_buffer; + unsigned char _M_buffer[sizeof(_M_ptr)]; }; template, diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any index e4709b1ce04..9ae29aab99f 100644 --- a/libstdc++-v3/include/std/any +++ b/libstdc++-v3/include/std/any @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Storage& operator=(const _Storage&) = delete; void* _M_ptr; - aligned_storage::type _M_buffer; + unsigned char _M_buffer[sizeof(_M_ptr)]; }; template, diff --git a/libstdc++-v3/testsuite/20_util/any/layout.cc b/libstdc++-v3/testsuite/20_util/any/layout.cc new file mode 100644 index 00000000000..5a7f4a8a280 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/any/layout.cc @@ -0,0 +1,22 @@ +// { dg-options "-Wno-deprecated-declarations" } +// { dg-do compile { target c++17 } } + +// Verify that r15-3419 did not change the layout of std::any + +#include + +namespace test { + class any { + union Storage { + constexpr Storage() : ptr(nullptr) { } + void* ptr; + std::aligned_storage::type buffer; + }; + + void (*manager)(int, const any*, void*); + Storage storage; + }; +} + +static_assert( sizeof(std::any) == sizeof(test::any) ); +static_assert( alignof(std::any) == alignof(test::any) );