re PR c++/51614 (ICE with ambiguous base class)
authorJason Merrill <jason@redhat.com>
Wed, 11 Jan 2012 03:04:49 +0000 (22:04 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 11 Jan 2012 03:04:49 +0000 (22:04 -0500)
PR c++/51614
* class.c (build_base_path): Diagnose ambiguous base.

From-SVN: r183088

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/inherit/ambig1.C [new file with mode: 0644]

index 4de8ba158dbe34340b027a54cd8efd1ddbdf022d..9b080fbaeb80226f334b6f946bd0272fbaba62c3 100644 (file)
@@ -1,5 +1,8 @@
 2012-01-10  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51614
+       * class.c (build_base_path): Diagnose ambiguous base.
+
        PR c++/51433
        * semantics.c (cxx_eval_call_expression): Always retry previously
        non-constant expressions.
index 79686a2cc0b255b6a5a6901fcb1f2e9f4bb0fc15..58c89d3dafaede7c434386951437e23ed0da7732 100644 (file)
@@ -266,10 +266,25 @@ build_base_path (enum tree_code code,
   if (want_pointer)
     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
 
+  if (code == PLUS_EXPR
+      && !SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe))
+    {
+      /* This can happen when adjust_result_of_qualified_name_lookup can't
+        find a unique base binfo in a call to a member function.  We
+        couldn't give the diagnostic then since we might have been calling
+        a static member function, so we do it now.  */
+      if (complain & tf_error)
+       {
+         tree base = lookup_base (probe, BINFO_TYPE (d_binfo),
+                                  ba_unique, NULL);
+         gcc_assert (base == error_mark_node);
+       }
+      return error_mark_node;
+    }
+
   gcc_assert ((code == MINUS_EXPR
               && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
-             || (code == PLUS_EXPR
-                 && SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe)));
+             || code == PLUS_EXPR);
 
   if (binfo == d_binfo)
     /* Nothing to do.  */
index 0afad2796a1723a0f156070f076839f6daa87423..f41975cfa2e9b0177732f0fc5a65f1397a7bba9c 100644 (file)
@@ -1,5 +1,8 @@
 2012-01-10  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51614
+       * g++.dg/inherit/ambig1.C: New.
+
        PR c++/51433
        * g++.dg/cpp0x/constexpr-cache1.C: New.
 
diff --git a/gcc/testsuite/g++.dg/inherit/ambig1.C b/gcc/testsuite/g++.dg/inherit/ambig1.C
new file mode 100644 (file)
index 0000000..3596bb5
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/51614
+
+struct A
+{
+  void foo();
+};
+
+struct B : A {};
+struct C : A {};
+
+struct D : B, C
+{
+  D() { A::foo(); }            // { dg-error "ambiguous" }
+};