OSDN Git Service

PR c++/51614
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 11 Jan 2012 03:04:49 +0000 (03:04 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 11 Jan 2012 03:04:49 +0000 (03:04 +0000)
* class.c (build_base_path): Diagnose ambiguous base.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183088 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 4de8ba1..9b080fb 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 79686a2..58c89d3 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 0afad27..f41975c 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" }
+};