From patchwork Fri Dec 2 09:35:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 128813 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 3CE66B6F69 for ; Fri, 2 Dec 2011 20:36:17 +1100 (EST) Received: (qmail 25992 invoked by alias); 2 Dec 2011 09:36:14 -0000 Received: (qmail 25861 invoked by uid 22791); 2 Dec 2011 09:36:13 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, KAM_ADVERT2, 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; Fri, 02 Dec 2011 09:35:57 +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 pB29Zuog006199 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 2 Dec 2011 04:35:56 -0500 Received: from localhost (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pB29Zs9u022883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 2 Dec 2011 04:35:56 -0500 Received: by localhost (Postfix, from userid 500) id 4B92529C134; Fri, 2 Dec 2011 10:35:54 +0100 (CET) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] PR c++/51289 - ICE with alias template for bound template References: <4ED405F0.1080903@redhat.com> <4ED5091A.8040707@redhat.com> <4ED6651D.70006@redhat.com> X-URL: http://www.redhat.com Date: Fri, 02 Dec 2011 10:35:54 +0100 In-Reply-To: (Dodji Seketeli's message of "Wed, 30 Nov 2011 22:18:38 +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 Dodji Seketeli writes: > Jason Merrill writes: > >> I guess let's check DECL_ORIGINAL_TYPE instead of TREE_TYPE for alias >> templates. > > Like the below that I am currently bootstrapping? Finally this is what passed bootstrap and testing on x86_64-unknown-linux-gnu against trunk. From: Dodji Seketeli Date: Sat, 26 Nov 2011 11:50:43 +0100 Subject: [PATCH] PR c++/51289 - ICE with alias template for bound template template parm gcc/cp/ PR c++/51289 * cp-tree.h (TYPE_TEMPLATE_INFO): Rewrite this accessor macro to better support aliased types. (TYPE_ALIAS_P): Don't crash on TYPE_NAME nodes that are not TYPE_DECL. * pt.c (find_parameter_packs_r): Handle types aliases. (push_template_decl_real): Check for bare parameter packs in the underlying type of an alias template. gcc/PR51289/gcc/testsuite/ PR c++/51289 * g++.dg/cpp0x/alias-decl-17.C: New test. --- gcc/cp/cp-tree.h | 28 ++++++++++++++++++---------- gcc/cp/pt.c | 19 ++++++++++++++++++- gcc/testsuite/g++.dg/cpp0x/alias-decl-17.C | 21 +++++++++++++++++++++ 3 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-17.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 3f4f408..b821928 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -2553,6 +2553,7 @@ extern void decl_shadowed_for_var_insert (tree, tree); #define TYPE_ALIAS_P(NODE) \ (TYPE_P (NODE) \ && TYPE_NAME (NODE) \ + && TREE_CODE (TYPE_NAME (NODE)) == TYPE_DECL \ && TYPE_DECL_ALIAS_P (TYPE_NAME (NODE))) /* For a class type: if this structure has many fields, we'll sort them @@ -2605,17 +2606,24 @@ extern void decl_shadowed_for_var_insert (tree, tree); (LANG_TYPE_CLASS_CHECK (BOUND_TEMPLATE_TEMPLATE_PARM_TYPE_CHECK (NODE)) \ ->template_info) -/* Template information for an ENUMERAL_, RECORD_, or UNION_TYPE. */ +/* Template information for an ENUMERAL_, RECORD_, UNION_TYPE, or + BOUND_TEMPLATE_TEMPLATE_PARM type. Note that if NODE is a + specialization of an alias template, this accessor returns the + template info for the alias template, not the one (if any) for the + template of the underlying type. */ #define TYPE_TEMPLATE_INFO(NODE) \ - (TREE_CODE (NODE) == ENUMERAL_TYPE \ - ? ENUM_TEMPLATE_INFO (NODE) : \ - (TREE_CODE (NODE) == BOUND_TEMPLATE_TEMPLATE_PARM \ - ? TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (NODE) : \ - ((CLASS_TYPE_P (NODE) && !TYPE_ALIAS_P (NODE)) \ - ? CLASSTYPE_TEMPLATE_INFO (NODE) \ - : ((TYPE_NAME (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))) \ - ? (DECL_TEMPLATE_INFO (TYPE_NAME (NODE))) \ - : NULL_TREE)))) + (TYPE_ALIAS_P (NODE) \ + ? ((TYPE_NAME (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))) \ + ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE)) \ + : NULL_TREE) \ + : ((TREE_CODE (NODE) == ENUMERAL_TYPE) \ + ? ENUM_TEMPLATE_INFO (NODE) \ + : ((TREE_CODE (NODE) == BOUND_TEMPLATE_TEMPLATE_PARM) \ + ? TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (NODE) \ + : (CLASS_TYPE_P (NODE) \ + ? CLASSTYPE_TEMPLATE_INFO (NODE) \ + : NULL_TREE)))) + /* Set the template information for an ENUMERAL_, RECORD_, or UNION_TYPE to VAL. */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4725080..ee3a3ab 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2976,6 +2976,20 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) (struct find_parameter_pack_data*)data; bool parameter_pack_p = false; + /* Handle type aliases/typedefs. */ + if (TYPE_P (t) + && TYPE_NAME (t) + && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL + && TYPE_DECL_ALIAS_P (TYPE_NAME (t))) + { + if (TYPE_TEMPLATE_INFO (t)) + cp_walk_tree (&TYPE_TI_ARGS (t), + &find_parameter_packs_r, + ppd, ppd->visited); + *walk_subtrees = 0; + return NULL_TREE; + } + /* Identify whether this is a parameter pack or not. */ switch (TREE_CODE (t)) { @@ -4905,7 +4919,10 @@ push_template_decl_real (tree decl, bool is_friend) if (check_for_bare_parameter_packs (TYPE_RAISES_EXCEPTIONS (type))) TYPE_RAISES_EXCEPTIONS (type) = NULL_TREE; } - else if (check_for_bare_parameter_packs (TREE_TYPE (decl))) + else if (check_for_bare_parameter_packs ((TREE_CODE (decl) == TYPE_DECL + && TYPE_DECL_ALIAS_P (decl)) + ? DECL_ORIGINAL_TYPE (decl) + : TREE_TYPE (decl))) { TREE_TYPE (decl) = error_mark_node; return error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-17.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-17.C new file mode 100644 index 0000000..41b1c95 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-17.C @@ -0,0 +1,21 @@ +// Origin PR c++/51289 +// { dg-options "-std=c++11" } + +template class b> +struct foo { + template + using type = b; + template + b funca() {} + + template + type funcb() {} +}; + +// This is an additional test, to emit an error message when using +// unexpanded parameter packs in an alias declaration. +template +struct S {}; + +template +using A = S; // { dg-error "parameter packs not expanded" }