2010-05-12 Jason Merrill <jason@redhat.com>
+ * call.c (add_candidates): Distinguish between type(x) and
+ x.operator type().
+ (convert_class_to_reference): Set LOOKUP_NO_CONVERSION.
+ (build_new_method_call): Give better error for conversion op.
+
* call.c (add_candidates): Add first_arg and return_type parms.
Add special constructor/conversion op handling.
(convert_class_to_reference): Use it.
t = TREE_TYPE (reference_type);
+ /* We're performing a user-defined conversion to a desired type, so set
+ this for the benefit of add_candidates. */
+ flags |= LOOKUP_NO_CONVERSION;
+
for (; conversions; conversions = TREE_CHAIN (conversions))
{
tree fns = TREE_VALUE (conversions);
if (DECL_CONV_FN_P (fn))
{
check_converting = !!(flags & LOOKUP_ONLYCONVERTING);
- strict = DEDUCE_CONV;
+ if (flags & LOOKUP_NO_CONVERSION)
+ /* We're doing return_type(x). */
+ strict = DEDUCE_CONV;
+ else
+ /* We're doing x.operator return_type(). */
+ strict = DEDUCE_EXACT;
/* [over.match.funcs] For conversion functions, the function
is considered to be a member of the class of the implicit
object argument for the purpose of defining the type of
{
if (!COMPLETE_TYPE_P (basetype))
cxx_incomplete_type_error (instance_ptr, basetype);
+ else if (optype)
+ error ("no matching function for call to %<%T::operator %T(%A)%#V%>",
+ basetype, optype, build_tree_list_vec (user_args),
+ TREE_TYPE (TREE_TYPE (instance_ptr)));
else
{
char *pretty_name;
have already generated a temporary, such as reference
initialization and the catch parameter. */
#define DIRECT_BIND (1 << 4)
-/* User-defined conversions are not permitted. (Built-in conversions
- are permitted.) */
+/* We're performing a user-defined conversion, so more user-defined
+ conversions are not permitted (only built-in conversions). */
#define LOOKUP_NO_CONVERSION (1 << 5)
/* The user has explicitly called a destructor. (Therefore, we do
not need to check that the object is non-NULL before calling the
2010-05-12 Jason Merrill <jason@redhat.com>
+ * g++.dg/template/conv11.C: New.
+ * g++.dg/conversion/op1.C: Adjust expected error.
+
* g++.old-deja/g++.robertl/eb43.C: Prune "candidates" messages.
2010-05-12 H.J. Lu <hongjiu.lu@intel.com>
int fn (C c)
{
- return C::operator float(c); // { dg-error "operator U" }
+ return C::operator float(c); // { dg-error "operator float.C" }
}
--- /dev/null
+int i;
+struct A
+{
+ template <class T> operator T&() { return i; }
+};
+
+int main()
+{
+ A().operator int(); // { dg-error "operator int" }
+}