From patchwork Wed Oct 20 19:22:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 46447 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2107C3857C67 for ; Wed, 20 Oct 2021 19:24:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2107C3857C67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634757857; bh=gZ8hO+R45N1D4Flu0UTEdvSrbqU65tAkNw6g3EUCN9Q=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=MOH4deiqytzIiUXjSjw1ptedxfdLc15gTtHYWjdypZWK6P0KJ5DvyQ1zrI2BYEuoM mNbEgkEbC4BN6Yo3s/1b1sV1Mp71pE0shx4Q0c04EBbNnIHstpplSUClpDura71HgI 2rZEcOUBW4NKi8I0KMocgz9+sZ/E6hsgP2xJ+daM= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 673893857C6F for ; Wed, 20 Oct 2021 19:22:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 673893857C6F Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-530-K41Bg_UtN0y_6ITXA0ml7g-1; Wed, 20 Oct 2021 15:22:50 -0400 X-MC-Unique: K41Bg_UtN0y_6ITXA0ml7g-1 Received: by mail-vk1-f199.google.com with SMTP id m133-20020a1fee8b000000b002a4a62429beso5725683vkh.0 for ; Wed, 20 Oct 2021 12:22:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gZ8hO+R45N1D4Flu0UTEdvSrbqU65tAkNw6g3EUCN9Q=; b=Ct6vVGt0D3i4npPbJFwNCXB1rUa29U6CbcPLcZFQQEBVDHXyocE0ZO9QcMV3OjDKAb AHCvyMZnemUE3XpU7wjipHxReCxQYmxyHh/Z1gcO48h7HQp/AkbotmV3f11CkhNqvHny WvkfuTVDvLDCQY3Cuz13ouZnaf/uDRjMjp+RYSNCyM/NidsY5gz4WQT0ctwk6pMwYW1/ +fj9su40KLVQM0NlIbcSRogR/vm89XDt895WZ9Qz76fw7BltuyFROxMLuKok+WnWT4BO 49bM8WbZBaJ6TupX1USUuqeOZ3IxnGNCsvdo2ir2X+pqZ5c8kYH5was4dqS1825P7Osz 3vjA== X-Gm-Message-State: AOAM533tqTtpSe3o7xmSBaUdXia8fEmGnwvLmstY3gPfAGOVKFxhFdru SwYdFEe3SMNgNo/QkLdLVjgJVRhRGhTlf9td7ybxH73O2MWofNBUiKPGYk/yugtYushqu1Tpxj9 ZggCzr55ItIQk4+GNRqgE9r95k1qJYsCRFw== X-Received: by 2002:a67:e0c2:: with SMTP id m2mr1420069vsl.2.1634757770170; Wed, 20 Oct 2021 12:22:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMSx1V++ZQK61mg20hAmHdI29kbc+unxOL6xGlz2RydI/DsUI3nZ88K019AalRya4aa6hoKqOlCdzTxZZF820= X-Received: by 2002:a67:e0c2:: with SMTP id m2mr1420037vsl.2.1634757769926; Wed, 20 Oct 2021 12:22:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 20 Oct 2021 20:22:39 +0100 Message-ID: Subject: [committed] libstdc++: Add missing test for std::optional::transform(F&&) To: Tim Song X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: libstdc++ , gcc-patches Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On Wed, 20 Oct 2021 at 09:42, Jonathan Wakely wrote: > > On Wed, 20 Oct 2021 at 06:48, Tim Song wrote: > > > > On Tue, Oct 19, 2021 at 9:05 AM Jonathan Wakely via Gcc-patches > > wrote: > > > > > > +constexpr bool > > > +test_copy_elision() > > > +{ > > > + return true; > > > +} > > > + > > > +static_assert( test_copy_elision() ); > > > + > > > > This isn't much of a test :) > > The ultimate copy elision. The copies even get removed from the source code. > > Thanks for spotting it. I meant to check we're constructing directly > into the union member without materializing the temporary early. I'll > add that today. Fixed by the attached patch. Tested x86_64-linux, pushed to trunk. Thanks again! commit 4ba4b053151a20262d4b61eb4501aa1c48337abb Author: Jonathan Wakely Date: Wed Oct 20 20:12:28 2021 libstdc++: Add missing test for std::optional::transform(F&&) The test_copy_elision() function was supposed to ensure that the result is constructed directly in the std::optional, without early temporary materialization. But I forgot to write the test. libstdc++-v3/ChangeLog: * testsuite/20_util/optional/monadic/transform.cc: Check that an rvalue result is not materialized too soon. diff --git a/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc b/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc index d01ccb2e0f2..13977b8ba8d 100644 --- a/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc +++ b/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc @@ -110,6 +110,23 @@ static_assert( test_forwarding() ); constexpr bool test_copy_elision() { + struct immovable + { + constexpr immovable(int p) : power_level(p) { } + immovable(immovable&&) = delete; + + int power_level; + }; + + struct Force + { + constexpr immovable operator()(int i) const { return {i+1}; } + }; + + std::optional irresistible(9000); + std::optional object = irresistible.transform(Force{}); + VERIFY( object->power_level > 9000 ); + return true; }