This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH]: Fix 7919


Hi,
I've installed the attached obvious fix for 7919. We neglected to
convert from the derived class with a using declaration to the
base class which declared the function. This lead to incorrect
this pointers.

built & tested on i686-pc-linux-gnu.

nathan
--
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org

2002-09-15  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/7919
	* call.c (build_over_call): Convert this pointer for fns found by
	using decls.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.333
diff -c -3 -p -r1.333 call.c
*** cp/call.c	13 Sep 2002 18:08:15 -0000	1.333
--- cp/call.c	15 Sep 2002 17:49:01 -0000
*************** build_over_call (cand, args, flags)
*** 4336,4342 ****
        tree parmtype = TREE_VALUE (parm);
        tree argtype = TREE_TYPE (TREE_VALUE (arg));
        tree converted_arg;
! 
        if (ICS_BAD_FLAG (TREE_VEC_ELT (convs, i)))
  	pedwarn ("passing `%T' as `this' argument of `%#D' discards qualifiers",
  		    TREE_TYPE (argtype), fn);
--- 4336,4343 ----
        tree parmtype = TREE_VALUE (parm);
        tree argtype = TREE_TYPE (TREE_VALUE (arg));
        tree converted_arg;
!       tree base_binfo;
!       
        if (ICS_BAD_FLAG (TREE_VEC_ELT (convs, i)))
  	pedwarn ("passing `%T' as `this' argument of `%#D' discards qualifiers",
  		    TREE_TYPE (argtype), fn);
*************** build_over_call (cand, args, flags)
*** 4354,4359 ****
--- 4355,4369 ----
  				       TREE_VALUE (arg),
  				       cand->conversion_path,
  				       1);
+       /* If fn was found by a using declaration, the conversion path
+          will be to the derived class, not the base declaring fn. We
+          must convert from derived to base.  */
+       base_binfo = lookup_base (TREE_TYPE (TREE_TYPE (converted_arg)),
+ 				TREE_TYPE (parmtype), ba_ignore, NULL);
+       
+       converted_arg = build_base_path (PLUS_EXPR, converted_arg,
+ 				       base_binfo, 1);
+       
        converted_args = tree_cons (NULL_TREE, converted_arg, converted_args);
        parm = TREE_CHAIN (parm);
        arg = TREE_CHAIN (arg);
// { dg-do run }

// Copyright (C) 2002 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Sep 2002 <nathan@codesourcery.com>

// PR 7919. Methods found via using decls didn't have their this
// pointers converted to the final base type.

struct Base {
  int m;
  protected:
  void *Return () { return this; }
};

struct Derived : Base {
  using Base::Return;
  virtual ~Derived () {}
};

int main ()
{
  Derived d;
  
  return static_cast <Base *> (&d) != d.Return ();
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]