@@ -7515,7 +7515,8 @@ extern tree build_if_nonnull (tree, tree, tsubst_flags_t);
extern tree get_parent_with_private_access (tree decl, tree binfo);
extern bool accessible_base_p (tree, tree, bool);
extern tree lookup_base (tree, tree, base_access,
- base_kind *, tsubst_flags_t);
+ base_kind *, tsubst_flags_t,
+ HOST_WIDE_INT = -1);
extern tree dcast_base_hint (tree, tree);
extern int accessible_p (tree, tree, bool);
extern int accessible_in_template_p (tree, tree);
@@ -5452,7 +5452,7 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type,
which is likely to be a waste of time (109678). */
if (is_empty_class (type)
&& CLASS_TYPE_P (optype)
- && DERIVED_FROM_P (type, optype))
+ && lookup_base (optype, type, ba_any, NULL, tf_none, off))
{
if (empty_base)
*empty_base = true;
@@ -56,6 +56,7 @@ static tree dfs_get_pure_virtuals (tree, void *);
struct lookup_base_data_s
{
+ HOST_WIDE_INT offset; /* Offset we want, or -1 if any. */
tree t; /* type being searched. */
tree base; /* The base type we're looking for. */
tree binfo; /* Found binfo. */
@@ -74,6 +75,22 @@ dfs_lookup_base (tree binfo, void *data_)
{
struct lookup_base_data_s *data = (struct lookup_base_data_s *) data_;
+ if (data->offset != -1)
+ {
+ /* We're looking for the type at a particular offset. */
+ int comp = compare_tree_int (BINFO_OFFSET (binfo), data->offset);
+ if (comp > 0)
+ /* Don't bother looking into bases laid out later; even if they
+ do virtually inherit from the base we want, we can get there
+ by another path. */
+ return dfs_skip_bases;
+ else if (comp != 0
+ && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
+ /* Right type, wrong offset. */
+ return dfs_skip_bases;
+ /* Fall through. */
+ }
+
if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
{
if (!data->binfo)
@@ -190,7 +207,7 @@ accessible_base_p (tree t, tree base, bool consider_local_p)
/* Lookup BASE in the hierarchy dominated by T. Do access checking as
ACCESS specifies. Return the binfo we discover. If KIND_PTR is
non-NULL, fill with information about what kind of base we
- discovered.
+ discovered. If OFFSET is other than -1, only match at that offset.
If the base is inaccessible, or ambiguous, then error_mark_node is
returned. If the tf_error bit of COMPLAIN is not set, no error
@@ -198,7 +215,8 @@ accessible_base_p (tree t, tree base, bool consider_local_p)
tree
lookup_base (tree t, tree base, base_access access,
- base_kind *kind_ptr, tsubst_flags_t complain)
+ base_kind *kind_ptr, tsubst_flags_t complain,
+ HOST_WIDE_INT offset /* = -1 */)
{
tree binfo;
tree t_binfo;
@@ -246,8 +264,9 @@ lookup_base (tree t, tree base, base_access access,
data.base = base;
data.binfo = NULL_TREE;
data.ambiguous = data.via_virtual = false;
- data.repeated_base = CLASSTYPE_REPEATED_BASE_P (t);
+ data.repeated_base = (offset == -1) && CLASSTYPE_REPEATED_BASE_P (t);
data.want_any = access == ba_any;
+ data.offset = offset;
dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data);
binfo = data.binfo;