* search.c (binfo_direct_p): New.
* name-lookup.c (do_class_using_decl): Use it.
From-SVN: r249797
+2017-06-29 Jason Merrill <jason@redhat.com>
+
+ PR c++/81164 - ICE with invalid inherited constructor.
+ * search.c (binfo_direct_p): New.
+ * name-lookup.c (do_class_using_decl): Use it.
+
2017-06-29 Nathan Sidwell <nathan@acm.org>
* cp-tree.h (THIS_NAME, IN_CHARGE_NAME, VTBL_PTR_TYPE,
extern tree dfs_walk_once (tree, tree (*) (tree, void *),
tree (*) (tree, void *), void *);
extern tree binfo_via_virtual (tree, tree);
+extern bool binfo_direct_p (tree);
extern tree build_baselink (tree, tree, tree, tree);
extern tree adjust_result_of_qualified_name_lookup
(tree, tree, tree);
return NULL_TREE;
}
}
- else if (name == ctor_identifier
- && BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo)))
+ else if (name == ctor_identifier && !binfo_direct_p (binfo))
{
error ("cannot inherit constructors from indirect base %qT", scope);
return NULL_TREE;
return NULL_TREE;
}
+/* BINFO is for a base class in some hierarchy. Return true iff it is a
+ direct base. */
+
+bool
+binfo_direct_p (tree binfo)
+{
+ tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
+ if (BINFO_INHERITANCE_CHAIN (d_binfo))
+ /* A second inheritance chain means indirect. */
+ return false;
+ if (!BINFO_VIRTUAL_P (binfo))
+ /* Non-virtual, so only one inheritance chain means direct. */
+ return true;
+ /* A virtual base looks like a direct base, so we need to look through the
+ direct bases to see if it's there. */
+ tree b_binfo;
+ for (int i = 0; BINFO_BASE_ITERATE (d_binfo, i, b_binfo); ++i)
+ if (b_binfo == binfo)
+ return true;
+ return false;
+}
+
/* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
Find the equivalent binfo within whatever graph HERE is located.
This is the inverse of original_binfo. */
--- /dev/null
+// PR c++/81164
+// { dg-do compile { target c++11 } }
+
+struct A {};
+struct B : virtual A {};
+struct C : virtual A {};
+struct D : B,C { using A::A; }; // { dg-error "indirect" }