}
}
else if (IS_AGGR_TYPE (TREE_TYPE (from))
- && IS_AGGR_TYPE (TREE_TYPE (to)))
+ && IS_AGGR_TYPE (TREE_TYPE (to))
+ /* [conv.ptr]
+
+ An rvalue of type "pointer to cv D," where D is a
+ class type, can be converted to an rvalue of type
+ "pointer to cv B," where B is a base class (clause
+ _class.derived_) of D. If B is an inaccessible
+ (clause _class.access_) or ambiguous
+ (_class.member.lookup_) base class of D, a program
+ that necessitates this conversion is ill-formed. */
+ /* Therefore, we use DERIVED_FROM_P, and not
+ ACESSIBLY_UNIQUELY_DERIVED_FROM_P, in this test. */
+ && DERIVED_FROM_P (TREE_TYPE (to), TREE_TYPE (from)))
{
- if (DERIVED_FROM_P (TREE_TYPE (to), TREE_TYPE (from)))
- {
- from =
- cp_build_qualified_type (TREE_TYPE (to),
- cp_type_quals (TREE_TYPE (from)));
- from = build_pointer_type (from);
- conv = build_conv (PTR_CONV, from, conv);
- }
+ from =
+ cp_build_qualified_type (TREE_TYPE (to),
+ cp_type_quals (TREE_TYPE (from)));
+ from = build_pointer_type (from);
+ conv = build_conv (PTR_CONV, from, conv);
}
if (tcode == POINTER_TYPE)
the overload resolution is ambiguous, the initialization is
ill-formed. */
if (CLASS_TYPE_P (type))
- return build_special_member_call (NULL_TREE, complete_ctor_identifier,
- build_tree_list (NULL_TREE, expr),
- TYPE_BINFO (type),
- LOOKUP_NORMAL);
+ {
+ expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
+ build_tree_list (NULL_TREE, expr),
+ TYPE_BINFO (type),
+ LOOKUP_NORMAL);
+ return build_cplus_new (type, expr);
+ }
conv = implicit_conversion (type, TREE_TYPE (expr), expr,
LOOKUP_NORMAL);
if (!conv || ICS_BAD_FLAG (conv))
(TREE_TYPE (type))))
&& at_least_as_qualified_p (TREE_TYPE (type), intype))
{
- /* At this point we have checked all of the conditions except
- that B is not a virtual base class of D. That will be
- checked by build_base_path. */
- tree base = lookup_base (TREE_TYPE (type), intype, ba_any, NULL);
+ /* There is a standard conversion from "D*" to "B*" even if "B"
+ is ambiguous or inaccessible. Therefore, we ask lookup_base
+ to check these conditions. */
+ tree base = lookup_base (TREE_TYPE (type), intype, ba_check, NULL);
- /* Convert from B* to D*. */
+ /* Convert from "B*" to "D*". This function will check that "B"
+ is not a virtual base of "D". */
expr = build_base_path (MINUS_EXPR, build_address (expr),
base, /*nonnull=*/false);
/* Convert the pointer to a reference -- but then remember that
tree base;
check_for_casting_away_constness (intype, type, "static_cast");
- base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
- ba_check | ba_quiet, NULL);
+ base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype), ba_check,
+ NULL);
return build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false);
}