From patchwork Thu Dec 6 20:19:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 204317 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 13D532C0199 for ; Fri, 7 Dec 2012 07:20:07 +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=1355430008; 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=4OQ1dYc tzCJd90XHXtVhbj1icRs=; b=F0BfMWkg5HqdCKkOyCdE8htElf9190CUnijUwqB Zmdnsia0ZHYxWtZoebRClZ96Fn/enbivn7h/XUZqI6mTaJ7JtsUtXBI0YczgsIsL olT4JVwmQjJc+ikBYvz7k4vwtHYImgaAiCigaFkri8JVfUxJHjOrval4rmJq4cZu W9ak= 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=QMFGnQdb7W3iNq3D04/33Dme6/W/KD5yYrUDBcKcs7tRyup8rqPU5DFzOZu3tI FNEoK65vXJ5pYqlBlBBN9XhgL7STivv3/uhfLSvKH39jEw25uHN4Y4i+KmGTR087 Vj9Jgkwm6893+bXHPxbSFKSSxVOOHQtRHwZ2FtfkbPhFs=; Received: (qmail 15218 invoked by alias); 6 Dec 2012 20:19:52 -0000 Received: (qmail 15012 invoked by uid 22791); 6 Dec 2012 20:19:49 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, 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; Thu, 06 Dec 2012 20:19:41 +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 qB6KJfAf006492 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Dec 2012 15:19:41 -0500 Received: from [10.3.113.18] ([10.3.113.18]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qB6KJeWC004729 for ; Thu, 6 Dec 2012 15:19:40 -0500 Message-ID: <50C0FDDB.1080700@redhat.com> Date: Thu, 06 Dec 2012 15:19:39 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/54744 (typename typedef used in mem-initializer) 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 In the testcase, the derived class contains typedef typename derived::base_type::base_type base_type; and then the constructor uses 'base_type' in a mem-initializer. The lookup finds this typedef, and we then try to resolve it in order to determine whether it matches the current class. When we try to resolve derived::base_type we find the typedef, and proceed into infinite recursion. The pt.c hunk breaks this recursion by checking the recursion-break flag we already have in another place. The other hunks avoid the need to resolve the typename at all for this testcase. Tested x86_64-pc-linux-gnu, applying to trunk. Applying just the pt.c hunk to 4.7. commit 2459623f8dc5eb1a83ca589a4f6c4542825886f7 Author: Jason Merrill Date: Thu Dec 6 10:59:46 2012 -0500 PR c++/54744 * pt.c (resolve_typename_type): Check TYPENAME_IS_RESOLVING_P on scope. * init.c (expand_member_init): Check for being in a template first. * parser.c (cp_parser_mem_initializer_list): Only check class types for equivalence to the current class. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 76a31c1b..2206c16 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1370,8 +1370,8 @@ expand_member_init (tree name) tree virtual_binfo; int i; - if (same_type_p (basetype, current_class_type) - || current_template_parms) + if (current_template_parms + || same_type_p (basetype, current_class_type)) return basetype; class_binfo = TYPE_BINFO (current_class_type); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a010f1f..3566d74 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11592,7 +11592,7 @@ cp_parser_mem_initializer_list (cp_parser* parser) } /* Look for a target constructor. */ if (mem_initializer != error_mark_node - && TYPE_P (TREE_PURPOSE (mem_initializer)) + && CLASS_TYPE_P (TREE_PURPOSE (mem_initializer)) && same_type_p (TREE_PURPOSE (mem_initializer), current_class_type)) { maybe_warn_cpp0x (CPP0X_DELEGATING_CTORS); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c1e12f0..2f27e10 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -20079,7 +20079,16 @@ resolve_typename_type (tree type, bool only_current_p) /* If the SCOPE is itself a TYPENAME_TYPE, then we need to resolve it first before we can figure out what NAME refers to. */ if (TREE_CODE (scope) == TYPENAME_TYPE) - scope = resolve_typename_type (scope, only_current_p); + { + if (TYPENAME_IS_RESOLVING_P (scope)) + /* Given a class template A with a dependent base with nested type C, + typedef typename A::C::C C will land us here, as trying to resolve + the initial A::C leads to the local C typedef, which leads back to + A::C::C. So we break the recursion now. */ + return type; + else + scope = resolve_typename_type (scope, only_current_p); + } /* If we don't know what SCOPE refers to, then we cannot resolve the TYPENAME_TYPE. */ if (TREE_CODE (scope) == TYPENAME_TYPE) diff --git a/gcc/testsuite/g++.dg/template/meminit3.C b/gcc/testsuite/g++.dg/template/meminit3.C new file mode 100644 index 0000000..b682449 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/meminit3.C @@ -0,0 +1,12 @@ +// PR c++/54744 + +template +struct base { + typedef base base_type; +}; + +template +struct derived : base { + typedef typename derived::base_type::base_type base_type; + derived() : base_type() {} +};