This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ Patch] PR 37650
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 14 Oct 2008 11:06:59 +0200
- Subject: Re: [C++ Patch] PR 37650
- References: <48F3102A.1060107@oracle.com> <48F3A657.2050503@codesourcery.com>
Hi,
> I'd prefer the check go in push_template_decl_real with an assert in
> process_partial_specialization.
>
Ok. The below also regtests fine on x86_64-linux. As you can see, the
check in carried out unconditionally, because current_template_parms is
needed anyway, and I'm returning
error_mark_node otherwise, because this is obviously an error condition,
seems the safe thing to do. Ok?
Thanks,
Paolo.
///////////////////////
/cp
2008-10-14 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/37650
* pt.c (push_template_decl_real): Check that current_template_parms
is not null.
(process_partial_specialization): Assert current_template_parms not
null.
/testsuite
2008-10-14 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/37650
* g++.dg/template/crash83.C: New.
Index: testsuite/g++.dg/template/crash83.C
===================================================================
*** testsuite/g++.dg/template/crash83.C (revision 0)
--- testsuite/g++.dg/template/crash83.C (revision 0)
***************
*** 0 ****
--- 1,5 ----
+ // PR c++/37650
+
+ template<int> struct A {};
+
+ template<typename = class A<0>: > struct B {}; // { dg-error "explicit specialization|expected" }
Index: cp/pt.c
===================================================================
*** cp/pt.c (revision 141104)
--- cp/pt.c (working copy)
*************** process_partial_specialization (tree dec
*** 3292,3306 ****
tree maintmpl = CLASSTYPE_TI_TEMPLATE (type);
tree specargs = CLASSTYPE_TI_ARGS (type);
tree inner_args = INNERMOST_TEMPLATE_ARGS (specargs);
- tree inner_parms = INNERMOST_TEMPLATE_PARMS (current_template_parms);
tree main_inner_parms = DECL_INNERMOST_TEMPLATE_PARMS (maintmpl);
int nargs = TREE_VEC_LENGTH (inner_args);
! int ntparms = TREE_VEC_LENGTH (inner_parms);
int i;
int did_error_intro = 0;
struct template_parm_data tpd;
struct template_parm_data tpd2;
/* We check that each of the template parameters given in the
partial specialization is used in the argument list to the
specialization. For example:
--- 3292,3311 ----
tree maintmpl = CLASSTYPE_TI_TEMPLATE (type);
tree specargs = CLASSTYPE_TI_ARGS (type);
tree inner_args = INNERMOST_TEMPLATE_ARGS (specargs);
tree main_inner_parms = DECL_INNERMOST_TEMPLATE_PARMS (maintmpl);
+ tree inner_parms;
int nargs = TREE_VEC_LENGTH (inner_args);
! int ntparms;
int i;
int did_error_intro = 0;
struct template_parm_data tpd;
struct template_parm_data tpd2;
+ gcc_assert (current_template_parms);
+
+ inner_parms = INNERMOST_TEMPLATE_PARMS (current_template_parms);
+ ntparms = TREE_VEC_LENGTH (inner_parms);
+
/* We check that each of the template parameters given in the
partial specialization is used in the argument list to the
specialization. For example:
*************** push_template_decl_real (tree decl, bool
*** 3749,3756 ****
[temp.mem]. */
bool member_template_p = false;
! if (decl == error_mark_node)
! return decl;
/* See if this is a partial specialization. */
is_partial = (DECL_IMPLICIT_TYPEDEF_P (decl)
--- 3754,3761 ----
[temp.mem]. */
bool member_template_p = false;
! if (decl == error_mark_node || !current_template_parms)
! return error_mark_node;
/* See if this is a partial specialization. */
is_partial = (DECL_IMPLICIT_TYPEDEF_P (decl)