From patchwork Thu Nov 14 16:37:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 291299 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9FFDD2C0079 for ; Fri, 15 Nov 2013 03:37:34 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=wOxjJscT1zTUrvnlr U9XbmTEGzjYGlR23+0NqcRAoOg9ghq/jQWnBwcIi6TUnaE3GiTnbZ8zOvoTIP9KI XSEOFLZyXI6Bn0T+OZHImyb1Mo87+rdbZpe3nmCekubgYrA4v6ftB+yuGxCiXo/a 8Ats315Oq7ISQuWDBGLC5B675M= 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=D/WorWypad9n0J/eT5DrMKx kcfc=; b=MIjp2TT3dyjEsaixB+uQhHAKtFZ3ThDVRuFWk+UnMiA8FzLuocFkT32 JOgf0S3ulxvXzw4V60AKIvxHO4cvJJeokdlptM5hrE8g5Rdxl8w2B7qpSH9zahUS RysLrIn8lVKxNOa+fXTDbzzhoCxAmAqJKvCQpf5c2a08l7m0kW4o= Received: (qmail 12224 invoked by alias); 14 Nov 2013 16:37:24 -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 12214 invoked by uid 89); 14 Nov 2013 16:37:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_50, RDNS_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: aserp1040.oracle.com Received: from Unknown (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 14 Nov 2013 16:37:22 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rAEGbDIF001896 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 14 Nov 2013 16:37:14 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rAEGbCr0029178 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 14 Nov 2013 16:37:13 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rAEGbCEi003609; Thu, 14 Nov 2013 16:37:12 GMT Received: from poldo4.casa (/79.33.220.51) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Nov 2013 08:37:11 -0800 Message-ID: <5284FC35.40700@oracle.com> Date: Thu, 14 Nov 2013 17:37:09 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch/RFC PR c++/57887 (and dups) References: <5284C934.9040006@oracle.com> <5284E122.2040108@redhat.com> In-Reply-To: <5284E122.2040108@redhat.com> X-IsSubscribed: yes Hi, On 11/14/2013 03:41 PM, Jason Merrill wrote: > I don't think we need a new parameter; just pass the FIELD_DECL into > maybe_end_member_template_processing and adjust it appropriately. > > Also, call m_e_m_t_p from cp_parser_late_parsing_nsdmi rather than > cp_parser_class_specifier_1. Thanks, much simpler indeed. I'm finishing testing the below. Paolo. //////////////////////// /cp 2013-11-14 Paolo Carlini PR c++/57887 * parser.c (cp_parser_late_parsing_nsdmi): Call maybe_begin_member_template_processing. * pt.c (maybe_begin_member_template_processing): Handle NSDMIs. (inline_needs_template_parms): Adjust. /testsuite 2013-11-14 Paolo Carlini PR c++/57887 * g++.dg/cpp0x/nsdmi-template3.C: New. * g++.dg/cpp0x/nsdmi-template4.C: Likewise. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 204780) +++ cp/parser.c (working copy) @@ -23378,12 +23378,16 @@ cp_parser_late_parsing_nsdmi (cp_parser *parser, t { tree def; + maybe_begin_member_template_processing (field); + push_unparsed_function_queues (parser); def = cp_parser_late_parse_one_default_arg (parser, field, DECL_INITIAL (field), NULL_TREE); pop_unparsed_function_queues (parser); + maybe_end_member_template_processing (); + DECL_INITIAL (field) = def; } Index: cp/pt.c =================================================================== --- cp/pt.c (revision 204780) +++ cp/pt.c (working copy) @@ -151,7 +151,7 @@ static int for_each_template_parm (tree, tree_fn_t struct pointer_set_t*, bool); static tree expand_template_argument_pack (tree); static tree build_template_parm_index (int, int, int, tree, tree); -static bool inline_needs_template_parms (tree); +static bool inline_needs_template_parms (tree, bool); static void push_inline_template_parms_recursive (tree, int); static tree retrieve_local_specialization (tree); static void register_local_specialization (tree, tree); @@ -377,9 +377,9 @@ template_class_depth (tree type) Returns true if processing DECL needs us to push template parms. */ static bool -inline_needs_template_parms (tree decl) +inline_needs_template_parms (tree decl, bool nsdmi) { - if (! DECL_TEMPLATE_INFO (decl)) + if (!decl || (!nsdmi && ! DECL_TEMPLATE_INFO (decl))) return false; return (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (most_general_template (decl))) @@ -448,16 +448,23 @@ push_inline_template_parms_recursive (tree parmlis } } -/* Restore the template parameter context for a member template or - a friend template defined in a class definition. */ +/* Restore the template parameter context for a member template, a + friend template defined in a class definition, or a non-template + member of template class. */ void maybe_begin_member_template_processing (tree decl) { tree parms; int levels = 0; + bool nsdmi = TREE_CODE (decl) == FIELD_DECL; - if (inline_needs_template_parms (decl)) + if (nsdmi) + decl = (CLASSTYPE_TEMPLATE_INFO (DECL_CONTEXT (decl)) + ? TREE_TYPE (CLASSTYPE_TEMPLATE_INFO (DECL_CONTEXT (decl))) + : NULL_TREE); + + if (inline_needs_template_parms (decl, nsdmi)) { parms = DECL_TEMPLATE_PARMS (most_general_template (decl)); levels = TMPL_PARMS_DEPTH (parms) - processing_template_decl; Index: testsuite/g++.dg/cpp0x/nsdmi-template3.C =================================================================== --- testsuite/g++.dg/cpp0x/nsdmi-template3.C (revision 0) +++ testsuite/g++.dg/cpp0x/nsdmi-template3.C (working copy) @@ -0,0 +1,16 @@ +// PR c++/58760 +// { dg-do compile { target c++11 } } + +enum en +{ + a,b,c +}; + +struct B +{ + template + struct A + { + const int X = N; + }; +}; Index: testsuite/g++.dg/cpp0x/nsdmi-template4.C =================================================================== --- testsuite/g++.dg/cpp0x/nsdmi-template4.C (revision 0) +++ testsuite/g++.dg/cpp0x/nsdmi-template4.C (working copy) @@ -0,0 +1,24 @@ +// PR c++/57887 +// { dg-do compile { target c++11 } } + +struct B +{ + template + struct A + { + int X = N; + }; +}; + +template +struct C +{ + int Y = M; + + template + struct A + { + int X = N; + int Y = M; + }; +};