From patchwork Sat Jun 6 23:39:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 481687 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 158B8140129 for ; Sun, 7 Jun 2015 09:40:08 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=l2NgzT2h; dkim-atps=neutral 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:cc:subject:content-type; q=dns; s=default; b=KIAKg+yC3TBomPYEFjUIUnr+ufTi8azr8ljUWEy15Ig VWSlluehtzDC5wibZQJbFF423JbZdg16oPM5wXc7RyEf2VzeDDmEQ/pVDPytg1cU LyTAUijQX6qKxJLl6VBKeC7rgJGo0jbxU0Bi+EAAAvqCc5vLRyiD3Gw741pTyVbk = 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:cc:subject:content-type; s=default; bh=BL1KU94AJtSUij59Z/CXP2zSqzA=; b=l2NgzT2h5ALDqDc7J 51StjTDc0oth9gE7iOTlTLouiW6TIcbrVstmuzT7KqqEtJ89NyLbNlmoE9k4foHJ HAXFkFA4Mbj/JFhkbRrzJ0Kjt53kS+LC0euKNA3Nv6vW/1wOqX4PTaR0svV8W4gx waSkNxzGiTcpesJOKfWNPTBdQ0= Received: (qmail 34374 invoked by alias); 6 Jun 2015 23:40:02 -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 34362 invoked by uid 89); 6 Jun 2015 23:40:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-vn0-f49.google.com Received: from mail-vn0-f49.google.com (HELO mail-vn0-f49.google.com) (209.85.216.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 06 Jun 2015 23:40:00 +0000 Received: by vnbf129 with SMTP id f129so2972073vnb.2 for ; Sat, 06 Jun 2015 16:39:58 -0700 (PDT) X-Received: by 10.52.112.36 with SMTP id in4mr18320319vdb.3.1433633998293; Sat, 06 Jun 2015 16:39:58 -0700 (PDT) Received: from ?IPv6:2601:19b:400:a983:a2a8:cdff:fe3e:b48? ([2601:19b:400:a983:a2a8:cdff:fe3e:b48]) by mx.google.com with ESMTPSA id h14sm13390490vdj.0.2015.06.06.16.39.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Jun 2015 16:39:57 -0700 (PDT) Message-ID: <557384CB.1020301@acm.org> Date: Sat, 06 Jun 2015 19:39:55 -0400 From: Nathan Sidwell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Jason Merrill CC: GCC Patches Subject: [C++/58583] ICE instantiating NSDMIs This patch fixes 58582, a set of ICEs that happen instantiating NSDMIs. There are a couple of causes, both fixed. 1) instantiating the template while parsing an NSDMI of the template itself. We see a DEFAULT_ARG in get_nsdmi. Fixed by jumping to the existing error handling for the non-template case. 2) recursive instantiation of the NSDMI itself. As we instantiate lazily, we end up running out of stack. Fixed by creating a temporary DEFAULT_ARG and then detecting it on a subsequent recursion. I did contemplate having this direct to the same error as above, but decided against it, because this really is an instantiation problem not a parsing problem. built & tested on x86_64-linux, ok? nathan 2015-06-05 Nathan Sidwell cp/ PR c++/58583 * init.c (get_nsdmi): Check for DEFAULT_ARG in template case and protect it from recursive instantiation. testsuite/ PR c++/58583 * g++.dg/cpp0x/nsdmi-template14.C: New test. Index: cp/init.c =================================================================== --- cp/init.c (revision 224152) +++ cp/init.c (working copy) @@ -544,6 +544,7 @@ get_nsdmi (tree member, bool in_ctor) tree init; tree save_ccp = current_class_ptr; tree save_ccr = current_class_ref; + if (!in_ctor) { /* Use a PLACEHOLDER_EXPR when we don't have a 'this' parameter to @@ -551,22 +552,41 @@ get_nsdmi (tree member, bool in_ctor) current_class_ref = build0 (PLACEHOLDER_EXPR, DECL_CONTEXT (member)); current_class_ptr = build_address (current_class_ref); } + if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member)) { - /* Do deferred instantiation of the NSDMI. */ - init = (tsubst_copy_and_build - (DECL_INITIAL (DECL_TI_TEMPLATE (member)), - DECL_TI_ARGS (member), - tf_warning_or_error, member, /*function_p=*/false, - /*integral_constant_expression_p=*/false)); + init = DECL_INITIAL (DECL_TI_TEMPLATE (member)); + if (TREE_CODE (init) == DEFAULT_ARG) + goto unparsed; - init = digest_nsdmi_init (member, init); + /* Check recursive instantiation. */ + if (TREE_CODE (DECL_INITIAL (member)) == DEFAULT_ARG) + { + error ("recursive instantiation of non-static data member " + "initializer for %qD", member); + init = error_mark_node; + } + else + { + DECL_INITIAL (member) = make_node (DEFAULT_ARG); + + /* Do deferred instantiation of the NSDMI. */ + init = (tsubst_copy_and_build + (init, DECL_TI_ARGS (member), + tf_warning_or_error, member, /*function_p=*/false, + /*integral_constant_expression_p=*/false)); + init = digest_nsdmi_init (member, init); + + if (TREE_CODE (DECL_INITIAL (member)) == DEFAULT_ARG) + DECL_INITIAL (member) = void_node; + } } else { init = DECL_INITIAL (member); if (init && TREE_CODE (init) == DEFAULT_ARG) { + unparsed: error ("constructor required before non-static data member " "for %qD has been parsed", member); DECL_INITIAL (member) = error_mark_node; Index: testsuite/g++.dg/cpp0x/nsdmi-template14.C =================================================================== --- testsuite/g++.dg/cpp0x/nsdmi-template14.C (revision 0) +++ testsuite/g++.dg/cpp0x/nsdmi-template14.C (working copy) @@ -0,0 +1,23 @@ +// PR c++/58583 +// { dg-do compile { target c++11 } } + +template struct A // {dg-error "non-static data member initializer" } +{ + int i = (A<0>(), 0); // { dg-error "non-static data member initializer required before parsing" } { dg-error "synthesized method" } +}; + +template struct B +{ + B* p = new B; +}; + +B<1> x; // { dg-error "constructor required before non-static data member" } + +struct C +{ + template struct D + { + D* p = new D<0>; + }; +}; +