From patchwork Thu Jun 26 13:06:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 364537 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 13A96140087 for ; Thu, 26 Jun 2014 23:06:35 +1000 (EST) 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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=Vs4BHDw/laiQSCHgbvoqnulmp3uRlKR6FS8ANiHjJI0/YhesWb PK6KRnQGtFYQ+tkJ6iVX9coqHf3ALuvLR9gEKfZQhY8/n3LDHXxcl/Hn3zAipDCO 9WzHl5ca76SsUDV5tZ8ENdzzZ7gQrXC/CWHlrbBTZeR19NqB/MrqMp438= 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:cc:subject:message-id:mime-version:content-type; s= default; bh=0rNQIiOZtIOhRegSS3vFtgk4X84=; b=YLv/8UlFMsT6fZHEUKuH xNbkmjkR0iJHIU5d4ZuFk9Lgoho81TpXwcp4vf7mWkMbg9dv8vOyNO7gewTkJq08 smcpJhU3oUtHLTPzxhSlOI03BIR2q3Gy5z8baOGkui/kuDXTpsg+eLH//hUZR7rv FK/fKQt4+l53NyB23niEbwY= Received: (qmail 27291 invoked by alias); 26 Jun 2014 13:06:26 -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 27194 invoked by uid 89); 26 Jun 2014 13:06:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 26 Jun 2014 13:06:23 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5QD6M4F025951 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 26 Jun 2014 09:06:22 -0400 Received: from localhost (vpn1-4-174.ams2.redhat.com [10.36.4.174]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5QD6Lr2028117; Thu, 26 Jun 2014 09:06:22 -0400 Date: Thu, 26 Jun 2014 14:06:21 +0100 From: Jonathan Wakely To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com Subject: [patch] c++/58051 Implement Core 1579 Message-ID: <20140626130621.GJ2711@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) DR1579 relaxes [class.copy]/32 so that expressions in return statements can be looked up as rvalues even when they aren't the same type as the function return type. Implementing that seems as simple as removing the restriction on the types. Tested x86_64-linux, no regressions. OK for trunk? commit 45e8a7ceb267cafde4d4411563a3e84bbd49ad8c Author: Jonathan Wakely Date: Thu Jun 26 11:00:54 2014 +0100 gcc/cp: DR 1579 PR c++/58051 * typeck.c (check_return_expr): Lookup as an rvalue even when the types aren't the same. gcc/testsuite: * g++.dg/cpp0x/elision_conv.C: New. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 65dccf7..042e600 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -8607,7 +8607,7 @@ check_return_expr (tree retval, bool *no_warning) if (VOID_TYPE_P (functype)) return error_mark_node; - /* Under C++0x [12.8/16 class.copy], a returned lvalue is sometimes + /* Under C++11 [12.8/32 class.copy], a returned lvalue is sometimes treated as an rvalue for the purposes of overload resolution to favor move constructors over copy constructors. @@ -8618,8 +8618,6 @@ check_return_expr (tree retval, bool *no_warning) || TREE_CODE (retval) == PARM_DECL) && DECL_CONTEXT (retval) == current_function_decl && !TREE_STATIC (retval) - && same_type_p ((TYPE_MAIN_VARIANT (TREE_TYPE (retval))), - (TYPE_MAIN_VARIANT (functype))) /* This is only interesting for class type. */ && CLASS_TYPE_P (functype)) flags = flags | LOOKUP_PREFER_RVALUE; diff --git a/gcc/testsuite/g++.dg/cpp0x/elision_conv.C b/gcc/testsuite/g++.dg/cpp0x/elision_conv.C new file mode 100644 index 0000000..d778a0b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/elision_conv.C @@ -0,0 +1,18 @@ +// Core 1579 return by converting move constructor +// PR c++/58051 +// { dg-do compile { target c++11 } } + +struct A { + A() = default; + A(A&&) = default; +}; + +struct B { + B(A) { } +}; + +B f() +{ + A a; + return a; +}