aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2004-08-24 16:06:22 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2004-08-24 16:06:22 +0000
commitf8ad2d219e145753abb13bf84b606a41df1ad5bb (patch)
tree86fd999adb0b2315ae129f8e8afc5084c8e45778 /gcc
parent97dc04b39a0435315f95512f5214d22cabe67e16 (diff)
downloadgcc-f8ad2d219e145753abb13bf84b606a41df1ad5bb.zip
gcc-f8ad2d219e145753abb13bf84b606a41df1ad5bb.tar.gz
gcc-f8ad2d219e145753abb13bf84b606a41df1ad5bb.tar.bz2
re PR c++/16889 (ambiguity is not detected)
cp: PR c++/16889 * (is_subobject_of_p): Resurrect & optimize. (lookup_field_r): Use it. testsuite: PR c++/16889 * g++.dg/lookup/ambig[12].C: New. From-SVN: r86488
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/search.c28
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/lookup/ambig1.C17
-rw-r--r--gcc/testsuite/g++.dg/lookup/ambig2.C17
5 files changed, 70 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 9ac0c74..cc0a961 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2004-08-24 Nathan Sidwell <nathan@codesourcery.com>
+
+ PR c++/16889
+ * (is_subobject_of_p): Resurrect & optimize.
+ (lookup_field_r): Use it.
+
2004-08-24 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/16706
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 81226d1..4aadf78 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -45,6 +45,7 @@ struct vbase_info
tree inits;
};
+static int is_subobject_of_p (tree, tree);
static tree dfs_check_overlap (tree, void *);
static tree dfs_no_overlap_yet (tree, int, void *);
static base_kind lookup_base_r (tree, tree, base_access, bool, tree *);
@@ -1018,7 +1019,6 @@ template_self_reference_p (tree type, tree decl)
&& DECL_NAME (decl) == constructor_name (type));
}
-
/* Nonzero for a class member means that it is shared between all objects
of that class.
@@ -1048,6 +1048,26 @@ shared_member_p (tree t)
return 0;
}
+/* Routine to see if the sub-object denoted by the binfo PARENT can be
+ found as a base class and sub-object of the object denoted by
+ BINFO. */
+
+static int
+is_subobject_of_p (tree parent, tree binfo)
+{
+ tree probe;
+
+ for (probe = parent; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
+ {
+ if (probe == binfo)
+ return 1;
+ if (BINFO_VIRTUAL_P (probe))
+ return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (binfo))
+ != NULL_TREE);
+ }
+ return 0;
+}
+
/* DATA is really a struct lookup_field_info. Look for a field with
the name indicated there in BINFO. If this function returns a
non-NULL value it is the result of the lookup. Called from
@@ -1115,12 +1135,14 @@ lookup_field_r (tree binfo, void *data)
/* If the lookup already found a match, and the new value doesn't
hide the old one, we might have an ambiguity. */
- if (lfi->rval_binfo && !original_binfo (lfi->rval_binfo, binfo))
+ if (lfi->rval_binfo
+ && !is_subobject_of_p (lfi->rval_binfo, binfo))
+
{
if (nval == lfi->rval && shared_member_p (nval))
/* The two things are really the same. */
;
- else if (original_binfo (binfo, lfi->rval_binfo))
+ else if (is_subobject_of_p (binfo, lfi->rval_binfo))
/* The previous value hides the new one. */
;
else
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7264db7..313d5a2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-08-24 Nathan Sidwell <nathan@codesourcery.com>
+
+ PR c++/16889
+ * g++.dg/lookup/ambig[12].C: New.
+
2004-08-24 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/16706
diff --git a/gcc/testsuite/g++.dg/lookup/ambig1.C b/gcc/testsuite/g++.dg/lookup/ambig1.C
new file mode 100644
index 0000000..1cf9ab4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/ambig1.C
@@ -0,0 +1,17 @@
+// { dg-do compile }
+
+// Copyright (C) 2004 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 24 Aug 2004 <nathan@codesourcery.com>
+// Origin: Wolfgang Bangerth <bangerth@dealii.org>
+
+// Bug 16889:Undetected ambiguity.
+
+struct B {
+ int f(); // { dg-error "int B::f" "" }
+};
+
+struct B1 : virtual B {};
+struct B2 : B {};
+struct BB : B1, B2 {};
+
+int i = BB().f(); // { dg-error "ambiguous" "" }
diff --git a/gcc/testsuite/g++.dg/lookup/ambig2.C b/gcc/testsuite/g++.dg/lookup/ambig2.C
new file mode 100644
index 0000000..4d423d1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/ambig2.C
@@ -0,0 +1,17 @@
+// { dg-do compile }
+
+// Copyright (C) 2004 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 24 Aug 2004 <nathan@codesourcery.com>
+// Origin: Wolfgang Bangerth <bangerth@dealii.org>
+
+// Bug 16889:Undetected ambiguity.
+
+struct B {
+ int i; // { dg-error "int B::i" "" }
+};
+
+struct B1 : virtual B {};
+struct B2 : B {};
+struct BB : B1, B2 {};
+
+int i = BB().i; // { dg-error "ambiguous" "" }