From patchwork Sun Mar 17 01:41:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 228261 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 01C7A2C00AD for ; Sun, 17 Mar 2013 12:41:35 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1364089296; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=AQXJpWm dZEORbjTTQ2s0SGYtw0c=; b=NyEkgSBm3Ses9RfIRX0K80sYKD00NvUkZz2ahGu V3EVSxL6mXpiZqGo6YXPHmIHf1bhhH1PUfCk0GthmMY2ARe+gXEiy+ES1z7V4ici rW5YcxtSdBOJBaELSmItIUQDGDegWPwJav1V7tSvIWQ+03aarEy7/AgkHSAh8eWg T3XA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=o1m/bW70vDBBIq2qpdc5TsY+0iRGs8YJk5WhKIGb+pxHaPI9qkYBqawtJgJij1 Lct1iRWN4uCG3slRP+hw1UyCsd7v2YdYY/RS3C8tgrwh+9v2h6Mk2MBRZhuLVpLo 4EgdT2cyjdV4XiQkbDPluxxUnbLU8iUJ8vkbbi7cPkZrc=; Received: (qmail 3058 invoked by alias); 17 Mar 2013 01:41:27 -0000 Received: (qmail 3048 invoked by uid 22791); 17 Mar 2013 01:41:26 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Sun, 17 Mar 2013 01:41:18 +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 r2H1fHXs018180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 16 Mar 2013 21:41:17 -0400 Received: from [10.3.113.56] (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2H1fGR7014101 for ; Sat, 16 Mar 2013 21:41:17 -0400 Message-ID: <51451F3C.1050709@redhat.com> Date: Sat, 16 Mar 2013 21:41:16 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/54359 ('this' in trailing-return-type with out-of-class method defn) 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 We were handling 'this' in a trailing-return-type properly for in-class declarations of member functions, but not for an out-of-class definition, where "member_p" isn't set. Tested x86_64-pc-linux-gnu, applying to trunk. commit 24c28e89e76e2deb3d3940b0461c322774afef26 Author: Jason Merrill Date: Mon Mar 11 06:15:26 2013 -0400 PR c++/54359 * parser.c (cp_parser_direct_declarator): Fix late return for out-of-class defn of member function. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 5add0c4..b0df636 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16366,6 +16366,8 @@ cp_parser_direct_declarator (cp_parser* parser, tree exception_specification; tree late_return; tree attrs; + bool memfn = (member_p || (pushed_scope + && CLASS_TYPE_P (pushed_scope))); is_declarator = true; @@ -16382,7 +16384,7 @@ cp_parser_direct_declarator (cp_parser* parser, attrs = cp_parser_std_attribute_spec_seq (parser); late_return = (cp_parser_late_return_type_opt - (parser, member_p ? cv_quals : -1)); + (parser, memfn ? cv_quals : -1)); /* Parse the virt-specifier-seq. */ virt_specifiers = cp_parser_virt_specifier_seq_opt (parser); diff --git a/gcc/testsuite/g++.dg/cpp0x/trailing8.C b/gcc/testsuite/g++.dg/cpp0x/trailing8.C new file mode 100644 index 0000000..304845e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/trailing8.C @@ -0,0 +1,25 @@ +// PR c++/54359 +// { dg-require-effective-target c++11 } + +int& ref(int& x) { return x; } +const int& ref(const int& x) { return x; } + +class A { + int x; + int f() const; + auto test1() const -> decltype(this); + auto test2() const -> decltype(ref(x)); + auto test3() const -> decltype(f()); +}; + +auto A::test1() const -> decltype(this) { + return this; +} + +auto A::test2() const -> decltype(ref(x)) { + return ref(x); +} + +auto A::test3() const -> decltype(f()) { + return f(); +}