[patch] Diagnose invalid destructor name in friend declarations

Volker Reichelt reichelt@igpm.rwth-aachen.de
Fri Dec 23 22:41:00 GMT 2005


Mark Mitchell wrote:
> Volker Reichelt wrote:

[snip]

> > 2005-12-16  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
> > 
> > 	* parser.c (cp_parser_unqualified_id): Check that destructor name
> > 	and scope match.
> > 
> > ===================================================================
> > --- gcc/gcc/cp/parser.c	(revision 108622)
> > +++ gcc/gcc/cp/parser.c	(working copy)
> > @@ -3419,6 +3419,16 @@
> >  	else if (type_decl == error_mark_node)
> >  	  return error_mark_node;
> >  
> > +	/* Check that destructor name and scope match.  */
> > +	if (declarator_p && scope
> > +	    && !same_type_p (scope, TREE_TYPE (type_decl)))
> 
> Use check_dtor_name; OK with that change.

Ok. There's a little problem, however: check_dtor_name expects a
BIT_NOT_EXPR as second argument:

  /* Returns nonzero iff the destructor name specified in NAME
     (a BIT_NOT_EXPR) matches BASETYPE.  The operand of NAME can take many
     forms...  */

  bool
  check_dtor_name (tree basetype, tree name)
  {
    name = TREE_OPERAND (name, 0);

I could rearrange the code in cp_parser_unqualified_id to build a
BIT_NOT_EXPR first, but I'd rather get rid of the line
    name = TREE_OPERAND (name, 0);
at the top of check_dtor_name. The only other user of check_dtor_name
(i.e. lookup_destructor) could then pass dtor_type instead of dtor_name
to check_dtor_name:

  static tree
  lookup_destructor (tree object, tree scope, tree dtor_name)
  {
    tree object_type = TREE_TYPE (object);
    tree dtor_type = TREE_OPERAND (dtor_name, 0);
    tree expr;

    if (scope && !check_dtor_name (scope, dtor_name))
      {

Which way would you prefer?

Regards,
Volker




More information about the Gcc-patches mailing list