From patchwork Mon Sep 19 15:17:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 671792 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 3sd8dz6kzNz9s9x for ; Tue, 20 Sep 2016 01:17:58 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=qOIxmlpr; 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:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=taY+JsMj6xk9Jk47 m81CYhcIzL8/+gQ9barPt9Jk389qBauOOr9m8geRxgCUAEmcGOy2VEcmPmxQUy4G dFCnqwGKY0iAna1UJzSxRHHFAfn0039iQSKhH8UzoREn/tYQ8DkH917dGTf7T8D8 h+qhoRO+P28tN8uMV47EI0SwyEE= 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:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=TcYN4itgzRY2c/lIC4gdrL hLk9U=; b=qOIxmlprmB4sucOG6pi2ke6YvEvy7BOE+JDF2V7As38uFBfdCHHZdR uQN4h+XBPqQ1hpgmc5aXi3t8P7mqcC9UxqaT+v8amePHUdRSMkYmvFieKdmGUFHa AYjAe4PpeMs7p0zFMf7GKEEOu03+98yhRNvldoGpBG4Mgi9FY0Yf8= Received: (qmail 80010 invoked by alias); 19 Sep 2016 15:17:50 -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 79991 invoked by uid 89); 19 Sep 2016 15:17:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=Rather, H*Ad:D*cx X-HELO: mail-qk0-f194.google.com Received: from mail-qk0-f194.google.com (HELO mail-qk0-f194.google.com) (209.85.220.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Sep 2016 15:17:39 +0000 Received: by mail-qk0-f194.google.com with SMTP id b204so9962666qkc.1 for ; Mon, 19 Sep 2016 08:17:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=bvwgGm+Yj8EUfwfz/0KMMh3UyQTvPfJpG9vXBPkp55E=; b=gNdfA4gJNas7/MH6AbQvIuDIpgUaLYvWlrBDFZUBhnu86/BlxZi0VGAkMNKQV9FgV9 P3XAldrMadYw+z0VArvzLDOTENPu4hdeGudT/CRSdMNLR4Luz+9Zn4D6hQyRxF7SENuj gIvlV/aay1IkGvc+WiDVgH4lLGwCMO6VMbFAG2OyX5HsTKpaaWCXeECt1zEEVfW6I4Lh gePvcIKtbg980xblRqYwfiXUVoM8JxT0walGNrpjO/GAAxL4/VhD3z+LBDYD3gBjnn5S bwcYR5/ow30kj4ccKd6iYVx6N46CUHDbAXSHoIdEfobC7oz83gjcDFlIaWEMsk/Eq8vJ H3/A== X-Gm-Message-State: AE9vXwMfW5Z3e1nmlWJ99SpfPjAp+TDXSKDPq/75LJs/zdkA8BO28J/pTdA4+L++Bw/N7Q== X-Received: by 10.55.36.131 with SMTP id k3mr29547520qkk.86.1474298257446; Mon, 19 Sep 2016 08:17:37 -0700 (PDT) Received: from [192.168.1.130] (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id p40sm13272635qtp.32.2016.09.19.08.17.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Sep 2016 08:17:36 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 19 Sep 2016 11:17:32 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches List Subject: Re: [PATCH] Fix PR c++/77639 (ICE during error recovery) In-Reply-To: Message-ID: References: <20160919120712.8930-1-patrick@parcs.ath.cx> User-Agent: Alpine 2.20.15 (DEB 166 2016-08-29) MIME-Version: 1.0 On Mon, 19 Sep 2016, Jason Merrill wrote: > > if (tree t = maybe_new_partial_specialization (type)) > > { > > + if (processing_template_parmlist) > > + { > > + /* Some syntactically invalid code can confuse the compiler into > > + defining a specialization from inside a template parameter > > + list. Bail out now so that we won't ICE later. */ > > + gcc_assert (seen_error ()); > > + return error_mark_node; > > + } > > Rather than decide it's a specialization and then fail, let's avoid > treating it as a specialization in the first place. I think we can > add a processing_template_parmlist check at the top where we avoid > trying to specialize lambdas. > > Jason > This works too. However I was playing around with the parser a bit and noticed that the following also fixes the ICE. It makes no sense to try to recover gracefully from a presumed missing "template <>" prefix when processing_template_parmlist. This is what seems to be responsible for creating the bogus specialization. Does this look OK or do you prefer adjusting maybe_process_partial_specialization()? gcc/cp/ChangeLog: PR c++/77639 * parser.c (cp_parser_class_head): When processing_template_parmlist, don't assume that a class-head starts an explicit specialization. gcc/testsuite/ChangeLog: PR c++/77639 * g++.dg/template/error-recovery4.C: New test. --- gcc/cp/parser.c | 1 + gcc/testsuite/g++.dg/template/error-recovery4.C | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/error-recovery4.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index fb88021..c03b9c2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -22025,6 +22025,7 @@ cp_parser_class_head (cp_parser* parser, it is not, try to recover gracefully. */ if (at_namespace_scope_p () && parser->num_template_parameter_lists == 0 + && !processing_template_parmlist && template_id_p) { /* Build a location of this form: diff --git a/gcc/testsuite/g++.dg/template/error-recovery4.C b/gcc/testsuite/g++.dg/template/error-recovery4.C new file mode 100644 index 0000000..1e52c6a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/error-recovery4.C @@ -0,0 +1,5 @@ +// PR c++/77639 + +template struct B {}; +template {}; // { dg-error "" } +B i;