This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: TEMPLATE_PARM_PARAMETER_PACK redundant check in find_parameter_packs_r
- From: Ian Lance Taylor <iant at google dot com>
- To: Larry Evans <cppljevans at suddenlink dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 23 Jun 2009 15:19:55 -0700
- Subject: Re: TEMPLATE_PARM_PARAMETER_PACK redundant check in find_parameter_packs_r
- References: <h1rbqf$6hj$1@ger.gmane.org>
Larry Evans <cppljevans@suddenlink.net> writes:
> At pt.c:2462
>
> http://gcc.gnu.org/viewcvs/trunk/gcc/cp/pt.c?revision=148666&view=markup
>
> there's:
>
> switch (TREE_CODE (t))
> {
> case TEMPLATE_PARM_INDEX:
> if (TEMPLATE_PARM_PARAMETER_PACK (t))
> parameter_pack_p = true;
> break;
>
> In gdb, macro exp shows:
>
> (gdb) macro exp TEMPLATE_PARM_PARAMETER_PACK(t)
> expands to: (((__extension__ ({ __typeof (t) const __t = (t); if
> (((enum tree_code) (__t)->base.code) != (TEMPLATE_PARM_INDEX))
> tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,
> (TEMPLATE_PARM_INDEX), 0); __t; }))->base.lang_flag_0))
>
> which I don't understand because it seems to just recheck
> that TREE_CODE is TEMPLATE_PARM_INDEX and if not issue an
> error message(from tree_check_failed). Why is there this
> redundant check for TREE_CODE(t)== TEMPLATE_PARM_INDEX?
> The only useful thing it does is return t->base.lang_flag_0.
>
> What am I missing?
You may be missing the fact that TEMPLATE_PARM_PARAMETER_PACK only
expands to code which checks t->base.code if ENABLE_TREE_CHECKING is
defined. This is the default in the development sources, but not on the
release branches. On release branches (or if you configure with
--enable-checking=no), TEMPLATE_PARM_PARAMETER_PACK really does just
return base.lang_flag_0.
Or, you may be missing the fact that TEMPLATE_PARM_PARAMETER_PACK is not
always called in a case where it is so very obvious that it is being
called on a TEMPLATE_PARM_INDEX tree (e.g., the call in
template_parameter_pack_p). Since it would always be wrong to call it
on a tree which is not a TEMPLATE_PARM_INDEX, but since there is no
compiler type checking (since everything has type tree) the code
verifies that the macro is being used correctly.
These kinds of runtime checks have caught many bugs early on and saved a
lot of debugging time.
Ian