// Search for a sequence of conversions from expression `e` to a destination // category c and type t. Expr& standard_conversion(Context& cxt, Expr& e, Type& t) { // No conversions are required if the types are the same. if (is_equivalent(e.type(), t)) return e; // Try a categorical conversion. Expr& c1 = convert_category(cxt, e, t); if (is_equivalent(c1.type(), t)) return c1; // Try a value conversion. Expr& c2 = convert_value(cxt, c1, t); if (is_equivalent(c2.type(), t)) return c2; // Try a qualification adjustment. Expr& c3 = convert_qualifier(cxt, c2, t); if (is_equivalent(c3.type(), t)) return c3; error(cxt, "cannot convert '{}' (type '{}') to '{}'", e, e.type(), t); throw Type_error(); }
// Try to find a standard conversion sequence from a source // expression `e` and a destination type `t`. // // FIXME: Should `t` be an object type? That is we should perform // conversions iff we can declare an object of type T? Expr& standard_conversion(Expr& e, Type& t) { Expr& c1 = convert_category(e, t); if (is_equivalent(c1.type(), t)) return c1; Expr& c2 = convert_value(c1, t); if (is_equivalent(c2.type(), t)) return c2; Expr& c3 = convert_qualifier(c2, t); if (is_equivalent(c3.type(), t)) return c3; // FIXME: Emit better diagnostics. throw std::runtime_error("conversion error"); }