Re: your mail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



```
bool
find_template_parameter_info::found (tree parm)
{
  if (TREE_CODE (parm) == TREE_LIST)
    parm = TREE_VALUE (parm);
  if (TREE_CODE (parm) == TYPE_DECL)
    parm = TREE_TYPE (parm);
  else
    parm = DECL_INITIAL (parm);
  gcc_checking_assert (TEMPLATE_PARM_P (parm));
  return parms.contains (parm);
}
```

Is there a reason why TREE_TYPE used only for TYPE_DECL, but not for
TEMPLATE_DECL ? process_template_parm initializes DECL_INITIAL for non type
template parameters, but  TYPE_DECL and TEMPLATE_DECL, stayed with nullptr,
on the other hand as I understood it always initializes TREE_TYPE.

cp/pt.cc::tree process_template_parm:
```
 if (parm && TREE_CODE (parm) == TEMPLATE_DECL)
{
 t = cxx_make_type (TEMPLATE_TEMPLATE_PARM);
...
 TREE_TYPE (result) = t;
...
}
      else
{
 t = cxx_make_type (TEMPLATE_TYPE_PARM);
 /* parm is either IDENTIFIER_NODE or NULL_TREE.  */
 decl = build_decl (parm_loc,
    TYPE_DECL, parm, t);
}
```
In other similar pieces of code the condition is for both for TYPE_DECL and
TEMLATE_DECL:

cp/pt.cc::tree template_parm_to_arg:
```
 if (DECL_P (t) && DECL_TEMPLATE_PARM_P (t))
    {
      if (TREE_CODE (t) == TYPE_DECL
 || TREE_CODE (t) == TEMPLATE_DECL)
t = TREE_TYPE (t);
      else
t = DECL_INITIAL (t);
    }
```
cp/pt.cc::tree get_template_parm_index:
```
if (TREE_CODE (parm) == PARM_DECL
      || TREE_CODE (parm) == CONST_DECL)
    parm = DECL_INITIAL (parm);
  else if (TREE_CODE (parm) == TYPE_DECL
  || TREE_CODE (parm) == TEMPLATE_DECL)
    parm = TREE_TYPE (parm);
```

Sorry if I ask stupid question.

On Thu, Mar 21, 2024 at 7:28 PM Segher Boessenkool <
segher@xxxxxxxxxxxxxxxxxxx> wrote:

> On Thu, Mar 21, 2024 at 07:12:23PM +0400, Centurion via Gcc-help wrote:
> > HI, I am new in gcc codebase. Can you explain please why we can't just
> use
> > TREE_TYPE(parm) for TEMLATE_TEMPLATE_PARM and why DECL_INITIAL is needed
> > for it? I tried to debug Bug 114377 and it seems to work fine. Thanks
>
> You cannot use TREE_TYPE if that would just access nonsense data.
>
> The wrong thing might still work, in many cases.  If you have no
> substantiation why your proposed change would work fine, chances are it
> does not.  Sorry.
>
>
> Segher
>
>
> > --- a/gcc/cp/pt.cc
> > +++ b/gcc/cp/pt.cc
> > @@ -11032,10 +11032,7 @@ find_template_parameter_info::found (tree parm)
> >  {
> >    if (TREE_CODE (parm) == TREE_LIST)
> >      parm = TREE_VALUE (parm);
> > -  if (TREE_CODE (parm) == TYPE_DECL)
> > -    parm = TREE_TYPE (parm);
> > -  else
> > -    parm = DECL_INITIAL (parm);
> > +  parm = TREE_TYPE(parm);
> >    gcc_checking_assert (TEMPLATE_PARM_P (parm));
> >    return parms.contains (parm);
> >  }
>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux