aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2002-09-15 18:16:11 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2002-09-15 18:16:11 +0000
commit3baab4840ec4c3b7af66cb4e69555e9bfd1cc934 (patch)
tree7288bac8898ce14ae76c73e6e1ed84936f70f177 /gcc
parentb0c2b2f9345175370ef1d485eb326a58486fd108 (diff)
downloadgcc-3baab4840ec4c3b7af66cb4e69555e9bfd1cc934.zip
gcc-3baab4840ec4c3b7af66cb4e69555e9bfd1cc934.tar.gz
gcc-3baab4840ec4c3b7af66cb4e69555e9bfd1cc934.tar.bz2
re PR c++/7919 (using declarations screw this pointer)
cp: PR c++/7919 * call.c (build_over_call): Convert this pointer for fns found by using decls. testsuite: * g++.dg/inherit/using2.C: New test. From-SVN: r57165
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/call.c12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/inherit/using2.C25
4 files changed, 46 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 21ab0c9..da49b54 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
2002-09-15 Kazu Hirata <kazu@cs.umass.edu>
* ChangeLog: Follow spelling conventions.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index b428145..46a6e23 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4336,7 +4336,8 @@ build_over_call (cand, args, flags)
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);
@@ -4354,6 +4355,15 @@ build_over_call (cand, args, flags)
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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d66527d..d0ca257 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2002-09-15 Nathan Sidwell <nathan@codesourcery.com>
+
+ * g++.dg/inherit/using2.C: New test.
+
2002-09-15 Kazu Hirata <kazu@cs.umass.edu>
* ChangeLog: Follow spelling conventions.
diff --git a/gcc/testsuite/g++.dg/inherit/using2.C b/gcc/testsuite/g++.dg/inherit/using2.C
new file mode 100644
index 0000000..19f06e9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/inherit/using2.C
@@ -0,0 +1,25 @@
+// { 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 ();
+}