c++: Better diagnostic in converted const expr.
authorJason Merrill <jason@redhat.com>
Mon, 11 May 2020 19:39:44 +0000 (15:39 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 11 May 2020 19:41:15 +0000 (15:41 -0400)
This improves the diagnostic from

error: could not convert ‘((A<>*)(void)0)->A<>::e’ from
       ‘<unresolved overloaded function type>’ to ‘bool’

to

error: cannot convert ‘A<>::e’ from type ‘void (A<>::)()’ to type ‘bool’

gcc/cp/ChangeLog
2020-05-11  Jason Merrill  <jason@redhat.com>

* call.c (implicit_conversion_error): Split out from...
(perform_implicit_conversion_flags): ...here.
(build_converted_constant_expr_internal): Use it.

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp0x/noexcept30.C
gcc/testsuite/g++.dg/cpp0x/noexcept58.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/crash87.C
gcc/testsuite/g++.dg/template/nontype13.C

index 3f13506..f2814c3 100644 (file)
@@ -1,5 +1,11 @@
 2020-05-11  Jason Merrill  <jason@redhat.com>
 
+       * call.c (implicit_conversion_error): Split out from...
+       (perform_implicit_conversion_flags): ...here.
+       (build_converted_constant_expr_internal): Use it.
+
+2020-05-11  Jason Merrill  <jason@redhat.com>
+
        PR c++/90748
        * parser.c (inject_parm_decls): Set current_class_ptr here.
        (cp_parser_direct_declarator): And here.
index aca12c7..85d670f 100644 (file)
@@ -4282,6 +4282,28 @@ build_user_type_conversion (tree totype, tree expr, int flags,
   return ret;
 }
 
+/* Give a helpful diagnostic when implicit_conversion fails.  */
+
+static void
+implicit_conversion_error (location_t loc, tree type, tree expr)
+{
+  tsubst_flags_t complain = tf_warning_or_error;
+
+  /* If expr has unknown type, then it is an overloaded function.
+     Call instantiate_type to get good error messages.  */
+  if (TREE_TYPE (expr) == unknown_type_node)
+    instantiate_type (type, expr, complain);
+  else if (invalid_nonstatic_memfn_p (loc, expr, complain))
+    /* We gave an error.  */;
+  else
+    {
+      range_label_for_type_mismatch label (TREE_TYPE (expr), type);
+      gcc_rich_location rich_loc (loc, &label);
+      error_at (&rich_loc, "could not convert %qE from %qH to %qI",
+               expr, TREE_TYPE (expr), type);
+    }
+}
+
 /* Worker for build_converted_constant_expr.  */
 
 static tree
@@ -4397,8 +4419,7 @@ build_converted_constant_expr_internal (tree type, tree expr,
   else
     {
       if (complain & tf_error)
-       error_at (loc, "could not convert %qE from %qH to %qI", expr,
-                 TREE_TYPE (expr), type);
+       implicit_conversion_error (loc, type, expr);
       expr = error_mark_node;
     }
 
@@ -11845,21 +11866,7 @@ perform_implicit_conversion_flags (tree type, tree expr,
   if (!conv)
     {
       if (complain & tf_error)
-       {
-         /* If expr has unknown type, then it is an overloaded function.
-            Call instantiate_type to get good error messages.  */
-         if (TREE_TYPE (expr) == unknown_type_node)
-           instantiate_type (type, expr, complain);
-         else if (invalid_nonstatic_memfn_p (loc, expr, complain))
-           /* We gave an error.  */;
-         else
-           {
-             range_label_for_type_mismatch label (TREE_TYPE (expr), type);
-             gcc_rich_location rich_loc (loc, &label);
-             error_at (&rich_loc, "could not convert %qE from %qH to %qI",
-                       expr, TREE_TYPE (expr), type);
-           }
-       }
+       implicit_conversion_error (loc, type, expr);
       expr = error_mark_node;
     }
   else if (processing_template_decl && conv->kind != ck_identity)
index 6a9f782..1075c69 100644 (file)
@@ -5,7 +5,7 @@
 template<typename A>
 struct F {
   template<typename B>
-  void f() noexcept(&F::template f<B>) {} // { dg-error "exception specification|convert" }
+  void f() noexcept(&F::template f<B>) {} // { dg-error "exception specification|convert|resolve" }
 };
 
 int main () {
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept58.C b/gcc/testsuite/g++.dg/cpp0x/noexcept58.C
new file mode 100644 (file)
index 0000000..0a145e0
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/90748
+// { dg-do compile { target c++11 } }
+
+template <class ...> class A
+{
+  void e ();
+  bool f (int() noexcept(e));  // { dg-error "::e" }
+};
+A<> b;
index af81edb..7da6623 100644 (file)
@@ -17,7 +17,7 @@ template <bool name>
 class BUG2 : BUG
 {
 public:
- typedef BUG1_5<name> ptr; // { dg-error "convert" }
+ typedef BUG1_5<name> ptr; // { dg-error "BUG::name" }
 };
 
 int main()
index 3250109..4d6b323 100644 (file)
@@ -11,7 +11,7 @@ struct Dummy
   template<bool B>
   void tester()
   {
-    bar<evil>()(); // { dg-error "constant|template|convert" }
+    bar<evil>()(); // { dg-error "constant|template|convert|member function" }
   }
   template<bool B>
   struct bar