This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCHes to improve overload resolution diagnostics

On 14 May 2014 18:47, Jason Merrill <> wrote:
> When I was working on DR 1571, I noticed that our diagnostics weren't very
> helpful for reference bindings (BZ 20332/21631) so I set out to treat
> lvalue/rvalue mismatches and cv-qual loss as a bad conversion rather than no
> conversion.  As I worked on that I kept noticing other things that I could
> tweak to improve diagnostics:
> We now explain what's wrong with near matches in overload resolution. As a
> result, I've changed to saying "candidate:" before every candidate to help
> users recognize when we're printing a new candidate rather than explanation
> of what was wrong with the previous one.
> We now get information about near-matches even with -pedantic.
> If we see ambiguous valid candidates, the diagnostic won't mention
> near-matches.  If we see a template candidate and ambiguous near-valid
> candidates, we will print all the candidates.
> Tested x86_64-pc-linux-gnu, applying to trunk.

This looks great. One minor nit: In this hunk, what is input_location
pointing at and why is that better than loc?

@@ -3195,18 +3217,37 @@ equal_functions (tree fn1, tree fn2)
 static void
 print_conversion_rejection (location_t loc, struct conversion_info *info)
+  tree from = info->from;
+  if (!TYPE_P (from))
+    from = lvalue_type (from);
   if (info->n_arg == -1)
-    /* Conversion of implicit `this' argument failed.  */
-    inform (loc, "  no known conversion for implicit "
-        "%<this%> parameter from %qT to %qT",
-        info->from_type, info->to_type);
+    {
+      /* Conversion of implicit `this' argument failed.  */
+      if (!TYPE_P (info->from))
+    /* A bad conversion for 'this' must be discarding cv-quals.  */
+    inform (input_location, "  passing %qT as %<this%> "
+        "argument discards qualifiers",
+        from);
+      else
+    inform (loc, "  no known conversion for implicit "
+        "%<this%> parameter from %qT to %qT",
+        from, info->to_type);
+    }
+  else if (!TYPE_P (info->from))
+    {
+      if (info->n_arg >= 0)
+    inform (loc, "  conversion of argument %d would be ill-formed:",
+        info->n_arg+1);
+      perform_implicit_conversion (info->to_type, info->from,
+                   tf_warning_or_error);
+    }
   else if (info->n_arg == -2)
     /* Conversion of conversion function return value failed.  */
     inform (loc, "  no known conversion from %qT to %qT",
-        info->from_type, info->to_type);
+        from, info->to_type);
     inform (loc, "  no known conversion for argument %d from %qT to %qT",
-        info->n_arg+1, info->from_type, info->to_type);
+        info->n_arg+1, from, info->to_type);

And too few spaces around '+'.

Also, are there other qualifiers of 'this' besides 'const'?



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]