|
|
2e9d4a |
2021-05-27 Jason Merrill <jason@redhat.com>
|
|
|
2e9d4a |
|
|
|
2e9d4a |
PR c++/100797
|
|
|
2e9d4a |
PR c++/95719
|
|
|
2e9d4a |
* call.c (build_over_call): Adjust base_binfo in
|
|
|
2e9d4a |
resolves_to_fixed_type_p case.
|
|
|
2e9d4a |
|
|
|
2e9d4a |
* g++.dg/inherit/virtual15.C: New test.
|
|
|
2e9d4a |
|
|
|
2e9d4a |
--- gcc/cp/call.c
|
|
|
2e9d4a |
+++ gcc/cp/call.c
|
|
|
2e9d4a |
@@ -9152,18 +9152,32 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
|
|
|
2e9d4a |
if (base_binfo == error_mark_node)
|
|
|
2e9d4a |
return error_mark_node;
|
|
|
2e9d4a |
}
|
|
|
2e9d4a |
- tree converted_arg = build_base_path (PLUS_EXPR, arg,
|
|
|
2e9d4a |
- base_binfo, 1, complain);
|
|
|
2e9d4a |
|
|
|
2e9d4a |
/* If we know the dynamic type of the object, look up the final overrider
|
|
|
2e9d4a |
in the BINFO. */
|
|
|
2e9d4a |
if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
|
|
|
2e9d4a |
&& resolves_to_fixed_type_p (arg))
|
|
|
2e9d4a |
{
|
|
|
2e9d4a |
- fn = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
|
|
|
2e9d4a |
- flags |= LOOKUP_NONVIRTUAL;
|
|
|
2e9d4a |
+ tree ov = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
|
|
|
2e9d4a |
+
|
|
|
2e9d4a |
+ /* And unwind base_binfo to match. If we don't find the type we're
|
|
|
2e9d4a |
+ looking for in BINFO_INHERITANCE_CHAIN, we're looking at diamond
|
|
|
2e9d4a |
+ inheritance; for now do a normal virtual call in that case. */
|
|
|
2e9d4a |
+ tree octx = DECL_CONTEXT (ov);
|
|
|
2e9d4a |
+ tree obinfo = base_binfo;
|
|
|
2e9d4a |
+ while (obinfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (obinfo), octx))
|
|
|
2e9d4a |
+ obinfo = BINFO_INHERITANCE_CHAIN (obinfo);
|
|
|
2e9d4a |
+ if (obinfo)
|
|
|
2e9d4a |
+ {
|
|
|
2e9d4a |
+ fn = ov;
|
|
|
2e9d4a |
+ base_binfo = obinfo;
|
|
|
2e9d4a |
+ flags |= LOOKUP_NONVIRTUAL;
|
|
|
2e9d4a |
+ }
|
|
|
2e9d4a |
}
|
|
|
2e9d4a |
|
|
|
2e9d4a |
+ tree converted_arg = build_base_path (PLUS_EXPR, arg,
|
|
|
2e9d4a |
+ base_binfo, 1, complain);
|
|
|
2e9d4a |
+
|
|
|
2e9d4a |
argarray[j++] = converted_arg;
|
|
|
2e9d4a |
parm = TREE_CHAIN (parm);
|
|
|
2e9d4a |
if (first_arg != NULL_TREE)
|
|
|
2e9d4a |
--- gcc/testsuite/g++.dg/inherit/virtual15.C
|
|
|
2e9d4a |
+++ gcc/testsuite/g++.dg/inherit/virtual15.C
|
|
|
2e9d4a |
@@ -0,0 +1,18 @@
|
|
|
2e9d4a |
+// PR c++/100797
|
|
|
2e9d4a |
+// { dg-do run }
|
|
|
2e9d4a |
+
|
|
|
2e9d4a |
+bool ok = false;
|
|
|
2e9d4a |
+struct S1 { virtual ~S1() {} };
|
|
|
2e9d4a |
+struct S2 { virtual void f1() = 0; };
|
|
|
2e9d4a |
+struct S3: S1, S2 {
|
|
|
2e9d4a |
+ void f1() { f2(); }
|
|
|
2e9d4a |
+ virtual void f2() = 0;
|
|
|
2e9d4a |
+};
|
|
|
2e9d4a |
+struct S4: S3 {
|
|
|
2e9d4a |
+ void f2() { ok = true; }
|
|
|
2e9d4a |
+ using S2::f1;
|
|
|
2e9d4a |
+};
|
|
|
2e9d4a |
+int main() {
|
|
|
2e9d4a |
+ S4().f1();
|
|
|
2e9d4a |
+ if (!ok) __builtin_abort ();
|
|
|
2e9d4a |
+}
|
|
|
2e9d4a |
--- gcc/testsuite/g++.dg/inherit/virtual15a.C
|
|
|
2e9d4a |
+++ gcc/testsuite/g++.dg/inherit/virtual15a.C
|
|
|
2e9d4a |
@@ -0,0 +1,19 @@
|
|
|
2e9d4a |
+// PR c++/100797 plus diamond inheritance
|
|
|
2e9d4a |
+// { dg-do run }
|
|
|
2e9d4a |
+
|
|
|
2e9d4a |
+bool ok = false;
|
|
|
2e9d4a |
+struct S1 { virtual ~S1() {} };
|
|
|
2e9d4a |
+struct S2 { virtual void f1() = 0; };
|
|
|
2e9d4a |
+struct S3: S1, virtual S2 {
|
|
|
2e9d4a |
+ void f1() { f2(); }
|
|
|
2e9d4a |
+ virtual void f2() = 0;
|
|
|
2e9d4a |
+};
|
|
|
2e9d4a |
+struct SX: virtual S2 { };
|
|
|
2e9d4a |
+struct S4: SX, S3 {
|
|
|
2e9d4a |
+ void f2() { ok = true; }
|
|
|
2e9d4a |
+ using S2::f1;
|
|
|
2e9d4a |
+};
|
|
|
2e9d4a |
+int main() {
|
|
|
2e9d4a |
+ S4().f1();
|
|
|
2e9d4a |
+ if (!ok) __builtin_abort ();
|
|
|
2e9d4a |
+}
|