From patchwork Sat Nov 19 14:05:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 126585 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 71981B7239 for ; Sun, 20 Nov 2011 01:05:41 +1100 (EST) Received: (qmail 15009 invoked by alias); 19 Nov 2011 14:05:39 -0000 Received: (qmail 15001 invoked by uid 22791); 19 Nov 2011 14:05:36 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, 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; Sat, 19 Nov 2011 14:05:17 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pAJE5GF1019100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 19 Nov 2011 09:05:16 -0500 Received: from localhost (ovpn-116-17.ams2.redhat.com [10.36.116.17]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pAJE5FVX027818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 19 Nov 2011 09:05:16 -0500 Received: by localhost (Postfix, from userid 500) id D998229C12D; Sat, 19 Nov 2011 15:05:14 +0100 (CET) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: [PATCH] PR c++/51194 - ICE with invalid alias template X-URL: http://www.redhat.com Date: Sat, 19 Nov 2011 15:05:14 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 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 Hello, Here we crash while looking up an instantiation of an erroneous member template. In the example of the patch below, when we look at the expression in #3, an error is (rightfully) triggered. As a result of 'bar' TT's argument (in #2) is foo, which takes 2 parameters. Then the partial instantiation of the member template 'mem' is ill-formed, as it is equivalent to: template<> template bar::P > In that expression foo is ill-formed as the declaration of foo in #1 doesn't for instance have a default argument for one of its parameters and so the number of template parameters and arguments don't match. An error_mark_node is thus inserted in the AST for foo in the expression bar::P >, and the type of the template bar::mem is error_mark_node. The problem is, when we go further to lookup bar::mem with the type of the 'mem' template being error_mark_node, we just crash. Now lookup_template_class_1 returns early when the type of the template is error_mark_node. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. From: Dodji Seketeli Date: Fri, 18 Nov 2011 19:35:04 +0100 Subject: [PATCH] PR c++/51194 - ICE with invalid alias template gcc/cp/ PR c++/51194 * pt.c (lookup_template_class_1): Go out early if the type of the template is error_mark_node. gcc/testsuite/ * g++.dg/cpp0x/alias-decl-15.C: New test. --- gcc/cp/pt.c | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/alias-decl-15.C | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-15.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 78e263f..049e3b2 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7270,6 +7270,12 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, int is_dependent_type; int use_partial_inst_tmpl = false; + if (template_type == error_mark_node) + /* An error occured while building the template TEMPL, and a + diagnostic has most certainly been emitted for that + already. Let's propagate that error. */ + return error_mark_node; + gen_tmpl = most_general_template (templ); parmlist = DECL_TEMPLATE_PARMS (gen_tmpl); parm_depth = TMPL_PARMS_DEPTH (parmlist); diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-15.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-15.C new file mode 100644 index 0000000..2bc9b11 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-15.C @@ -0,0 +1,17 @@ +// Origin PR c++/51194 +// { dg-options "-std=c++0x" } + +template //#1 +struct foo {}; // { dg-error "provided for|foo" } + +template +struct P {}; + +template class... TT> +struct bar { + template + using mem = P...>;//#2 { dg-error "wrong number of|arguments" } +}; + +bar::mem b;//#3 { dg-error "invalid type" } +