From patchwork Sat Jun 18 05:53:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 100892 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]) by ozlabs.org (Postfix) with SMTP id 9FF9EB6FE8 for ; Sat, 18 Jun 2011 15:54:04 +1000 (EST) Received: (qmail 31732 invoked by alias); 18 Jun 2011 05:54:03 -0000 Received: (qmail 31723 invoked by uid 22791); 18 Jun 2011 05:54:02 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 18 Jun 2011 05:53:36 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5I5rZOg023788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 18 Jun 2011 01:53:35 -0400 Received: from [127.0.0.1] ([10.3.113.18]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5I5rZ1v022807 for ; Sat, 18 Jun 2011 01:53:35 -0400 Message-ID: <4DFC3D5E.5080900@redhat.com> Date: Sat, 18 Jun 2011 01:53:34 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/49458 (rvalue reference to function and conversion ops) 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 Another special case for the rule that an rvalue reference to function is an lvalue. Tested x86_64-pc-linux-gnu, applying to trunk. commit df1f90245e5436ceadf6b3df5cc6f7ef7e0536c0 Author: Jason Merrill Date: Fri Jun 17 16:45:44 2011 -0400 PR c++/49458 * call.c (convert_class_to_reference_1): Allow binding function lvalue to rvalue reference. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index b43d078..05bf983 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1362,6 +1362,8 @@ convert_class_to_reference_1 (tree reference_type, tree s, tree expr, int flags) /* Don't allow binding of lvalues to rvalue references. */ if (TYPE_REF_IS_RVALUE (reference_type) + /* Function lvalues are OK, though. */ + && TREE_CODE (TREE_TYPE (reference_type)) != FUNCTION_TYPE && !TYPE_REF_IS_RVALUE (TREE_TYPE (TREE_TYPE (cand->fn)))) cand->second_conv->bad_p = true; } diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-func2.C b/gcc/testsuite/g++.dg/cpp0x/rv-func2.C new file mode 100644 index 0000000..b792342 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-func2.C @@ -0,0 +1,10 @@ +// PR c++/49458 +// { dg-options -std=c++0x } + +typedef void ftype(); + +struct A { + operator ftype&(void); +}; + +ftype &&frvref = A();