From patchwork Fri Aug 24 21:02:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 962092 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-484398-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DvqPEXRq"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41xtzJ4lm8z9ryt for ; Sat, 25 Aug 2018 07:03:07 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=MHDf6BYz1iedFLeX1hi8c6HJjgp5C+sbCuX4qD8HaTPzxsTKVxv3O dNawplL4JecJf3NiFv3dqp9YN84PFWLrI5bUyzXc2xmKbiOU+kvRQ2/fULLnC5cA v2PkkMW5NTGKGyoYu57T0NdG6KRdSUybb6dAEhm0uttxqf7MaEQAcU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=i0jXjMMJzTNISsSfP9rLqxrQiVo=; b=DvqPEXRqP3IwP7zhFy8y oZiwxJD7u2/Ulq122Hulux/ipUeOGu8NMkIUMjt71gw6T+PS6l4Ai2AokYdz4g15 gpf9Uz+i2f0vQFGFIaSujoo61Bsr0lGJLxasadPfzE+gnymUyEBMpnP9r9k9RoeI Cb5Z+Tu1BbhGUSSnUvbCr20= Received: (qmail 109230 invoked by alias); 24 Aug 2018 21:03:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 109217 invoked by uid 89); 24 Aug 2018 21:02:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Wait X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Aug 2018 21:02:58 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B8A74000783 for ; Fri, 24 Aug 2018 21:02:56 +0000 (UTC) Received: from redhat.com (ovpn-123-25.rdu2.redhat.com [10.10.123.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14B082157F49; Fri, 24 Aug 2018 21:02:55 +0000 (UTC) Date: Fri, 24 Aug 2018 17:02:54 -0400 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/87080, ICE with -Wpessimizing-move Message-ID: <20180824210254.GC13632@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) The problem in this testcase was that we were calling is_std_move_p from template context, which breaks in cp_get_fndecl_from_callee. This warning is not meant to warn while parsing a template, so I think we should apply this. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2018-08-24 Marek Polacek PR c++/87080 * typeck.c (maybe_warn_pessimizing_move): Do nothing in a template. * g++.dg/cpp0x/Wpessimizing-move5.C: New test. diff --git gcc/cp/typeck.c gcc/cp/typeck.c index 122d9dcd4b3..24647e29a55 100644 --- gcc/cp/typeck.c +++ gcc/cp/typeck.c @@ -9192,6 +9192,11 @@ maybe_warn_pessimizing_move (tree retval, tree functype) if (cxx_dialect < cxx11) return; + /* Wait until instantiation time, since we can't gauge if we should do + the NRVO until then. */ + if (processing_template_decl) + return; + /* This is only interesting for class types. */ if (!CLASS_TYPE_P (functype)) return; diff --git gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C index e69de29bb2d..02ad2113505 100644 --- gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C +++ gcc/testsuite/g++.dg/cpp0x/Wpessimizing-move5.C @@ -0,0 +1,14 @@ +// PR c++/87080 +// { dg-do compile { target c++11 } } +// { dg-options "-Wpessimizing-move" } + +struct a { + template a &operator<<(b); +}; +a c(); +template +a fn2() +{ + int d = 42; + return c() << d; +}