c++: Distinguish ambiguity from no valid candidate
authorJason Merrill <jason@redhat.com>
Mon, 7 Dec 2020 22:21:47 +0000 (17:21 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 8 Dec 2020 20:11:46 +0000 (15:11 -0500)
Several recent C++ features are specified to try overload resolution, and if
no viable candidate is found, do something else.  But our error return
doesn't distinguish between that situation and finding multiple viable
candidates that end up being ambiguous.  We're already trying to separately
return the single function we found even if it ends up being ill-formed for
some reason; for ambiguity let's pass back error_mark_node, to be
distinguished from NULL_TREE meaning no viable candidate.

gcc/cp/ChangeLog:

* call.c (build_new_op_1): Set *overload for ambiguity.
(build_new_method_call_1): Likewise.

gcc/cp/call.c

index f1e0bcb796b1baf0e9b97c95ef8811b76421b814..221e3de0c705a88fb7de75de1306fa3b61c53104 100644 (file)
@@ -6357,6 +6357,8 @@ build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags,
              print_z_candidates (loc, candidates);
            }
          result = error_mark_node;
+         if (overload)
+           *overload = error_mark_node;
        }
       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
        {
@@ -10438,6 +10440,8 @@ build_new_method_call_1 (tree instance, tree fns, vec<tree, va_gc> **args,
                free (pretty_name);
            }
          call = error_mark_node;
+         if (fn_p)
+           *fn_p = error_mark_node;
        }
       else
        {