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 DB3DE3858401 for ; Mon, 22 Aug 2022 21:02:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB3DE3858401 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_128_GCM_SHA256) id us-mta-483-kIvhm_oaMIGrHTKzszCceQ-1; Mon, 22 Aug 2022 17:02:15 -0400 X-MC-Unique: kIvhm_oaMIGrHTKzszCceQ-1 Received: by mail-qt1-f200.google.com with SMTP id bq11-20020a05622a1c0b00b003434f125b77so9300391qtb.20 for ; Mon, 22 Aug 2022 14:02:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc; bh=IPrnDtbAN/S9mZOdXZF81yM2SHinqSi+MhcGTIyYUZA=; b=3dLeJgkFx3HWBtkkPuwTfz2MRAHNsUEdG0/eRT7JIW5WFCbUryH5eQ3s7gwr1rov2K lYg3U1Y6CIbOt7XXzUtsaPQ+XRhQNFgNku13cRunDTTlYs99o0Cs91Ss66NRThQideyD RHi4wcZVqd7oHEWdwAobB3G+0TXITB06EwJygWirZpn9sD/M6RHR/Xfq5EFivZPTZYGC ecIXGdShzXZstcZDB5U7BdNSuj49IeR0jtNewgDa7X7KWLL/rs8/JnYBIgJYvgLUql/E HBHVW5cqsHHWHbFu+dkbIA50tVEwLKqXch+RtoN3/bSIlLLz6Mm7byWQ/L0ljZr2XL90 MR7w== X-Gm-Message-State: ACgBeo2bqMCEobQD6fSlIe1ZKX8WYi69i62tyI+Ht257HXKCjRCoLAJL JFe6TLwF5IaWXKcxqydarp/n1LZRjivNIhHdfBJetWRv5bb6GqL1stFvR9kCftbdM6dV6JHnNgr rJYRV6Ir2XrZYDe2KIQ== X-Received: by 2002:a05:6214:2249:b0:496:b529:846f with SMTP id c9-20020a056214224900b00496b529846fmr16984538qvc.121.1661202134659; Mon, 22 Aug 2022 14:02:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR7l2rqHDinEV1LUgeSxVRJR7g/lADAuArdfMcA1YSWSe9VitrW/Vgsqb8O0PMdfuC6vh6sCxw== X-Received: by 2002:a05:6214:2249:b0:496:b529:846f with SMTP id c9-20020a056214224900b00496b529846fmr16984522qvc.121.1661202134407; Mon, 22 Aug 2022 14:02:14 -0700 (PDT) Received: from redhat.com ([2601:184:4780:4310::e531]) by smtp.gmail.com with ESMTPSA id n18-20020a05620a295200b006b9593e2f68sm12559016qkp.4.2022.08.22.14.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 14:02:13 -0700 (PDT) Date: Mon, 22 Aug 2022 17:02:12 -0400 From: Marek Polacek To: Stephan Bergmann Cc: GCC Patches , Jason Merrill Subject: Re: [PATCH] c++: Extend -Wpessimizing-move to other contexts Message-ID: References: <20220802230447.721163-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.6 (2022-06-05) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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 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-List-Received-Date: Mon, 22 Aug 2022 21:02:21 -0000 On Mon, Aug 22, 2022 at 01:48:34PM +0200, Stephan Bergmann wrote: > On 16/08/2022 14:27, Marek Polacek via Gcc-patches wrote: > > Ping. (The other std::move patches depend on this one.) > > > "c++: Extend -Wpessimizing-move to other contexts" started to cause false > positive Thanks for reporting the problem. I'm testing a simple patch (appended below) and will post it once testing finishes. > > $ cat test.cc > > #include > > struct S1 { > > S1(); > > S1(S1 const &) = delete; > > S1(S1 &&); > > S1 operator =(S1 const &) = delete; > > S1 operator =(S1 &&); > > }; > > struct S2 { S2(S1); }; > > S2 f() { > > S1 s; > > return { std::move(s) }; > > } > > > > $ g++ -fsyntax-only -Wredundant-move test.cc > > test.cc: In function ‘S2 f()’: > > test.cc:12:27: warning: redundant move in return statement [-Wredundant-move] > > 12 | return { std::move(s) }; > > | ^ > > test.cc:12:27: note: remove ‘std::move’ call --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -10447,7 +10447,7 @@ maybe_warn_pessimizing_move (tree expr, tree type, bool return_p) return; /* A a = std::move (A()); */ - if (TREE_CODE (expr) == TREE_LIST) + if (TREE_CODE (expr) == TREE_LIST && !return_p) { if (list_length (expr) == 1) expr = TREE_VALUE (expr); @@ -10456,7 +10456,7 @@ maybe_warn_pessimizing_move (tree expr, tree type, bool return_p) } /* A a = {std::move (A())}; A a{std::move (A())}; */ - else if (TREE_CODE (expr) == CONSTRUCTOR) + else if (TREE_CODE (expr) == CONSTRUCTOR && !return_p) { if (CONSTRUCTOR_NELTS (expr) == 1) expr = CONSTRUCTOR_ELT (expr, 0)->value; Marek