Hi,
On Mon, Apr 16, 2012 at 12:42 AM, Marc Glisse<marc.gli...@inria.fr>  wrote:
On Sun, 15 Apr 2012, Gabriel Dos Reis wrote:

a hybrid approach; I would suggest something like this: (a) if caret
is in effect, then print
the caret pointing to the symbol in question; otherwise (b) print the
symbol and the type (as suggested by Marc).

I may have forgotten the details, but looking at the beginning of the PR,
don't we always want the types?
Yes.
Ok, then do I understand correctly that we want something like the below? First, If the caret is not active, we print the reconstructed expression. Then always the types.

I *think* things are fine translation-wise (I generated and inspected gcc.pot) and otherwise patch regtests fine on x86_64-linux (well, by default, when the caret is active, the behavior should be identical to what I posted about a month ago)

Thanks,
Paolo.

/////////////////
/cp
2012-04-16  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/49152
        * call.c (op_error): Print types; when flag_diagnostics_show_caret
        is false print expressions too.
        (op_error_string): Add.

/testsuite
2012-04-16  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/49152
        * g++.dg/diagnostic/operator1.C: New.
        * g++.dg/ext/label5.C: Adjust.
        * g++.dg/ext/va-arg1.C: Likewise.
        * g++.dg/other/error20.C: Likewise.
        * g++.dg/other/error20.C: Likewise.
        * g++.dg/other/error16.C: Likewise.
        * g++.dg/other/error10.C: Likewise.
        * g++.dg/parse/error30.C: Likewise.
        * g++.dg/cpp0x/lambda/lambda-err1.C: Likewise.
Index: testsuite/g++.dg/ext/label5.C
===================================================================
--- testsuite/g++.dg/ext/label5.C       (revision 186473)
+++ testsuite/g++.dg/ext/label5.C       (working copy)
@@ -2,5 +2,5 @@
 // PR c++/24052
 
 struct A { };
-int main() { b: A() && && b; } // { dg-error "A\\(\\) && && *b" }
+int main() { b: A() && && b; } // { dg-error "operand types are 'A' and 
'void\\*'" }
 // { dg-message "candidate|operator&&|no known conversion" "additional" { 
target *-*-* } 5 }
Index: testsuite/g++.dg/ext/va-arg1.C
===================================================================
--- testsuite/g++.dg/ext/va-arg1.C      (revision 186473)
+++ testsuite/g++.dg/ext/va-arg1.C      (working copy)
@@ -4,5 +4,5 @@ struct A {};
 
 void foo()
 {
-  ++__builtin_va_arg(0, A); // { dg-error "'\\+\\+va_arg\\(0, A\\)'" }
+  ++__builtin_va_arg(0, A); // { dg-error "operand type is 'A'" }
 }
Index: testsuite/g++.dg/other/error20.C
===================================================================
--- testsuite/g++.dg/other/error20.C    (revision 186473)
+++ testsuite/g++.dg/other/error20.C    (working copy)
@@ -8,6 +8,6 @@ struct A                        // { dg-message "operator=|no 
known con
 
 void bar (A& a)
 {
-  a.foo () = 0; // { dg-error "A::foo\\(\\) = 0" }
+  a.foo () = 0; // { dg-error "operand types are 'A' and 'int'" }
   // { dg-message "candidate" "candidate note" { target *-*-* } 11 }
 }   
Index: testsuite/g++.dg/other/error16.C
===================================================================
--- testsuite/g++.dg/other/error16.C    (revision 186473)
+++ testsuite/g++.dg/other/error16.C    (working copy)
@@ -10,5 +10,5 @@ typedef Outer<X> XOuter;
 
 int main() {
   Outer<int>  ab;
-  ab.foo() == 1; // { dg-error "ab.Outer" }
+  ab.foo() == 1; // { dg-error "operand types are 'Outer<int>::Inner' and 
'int'" }
 }
Index: testsuite/g++.dg/other/error10.C
===================================================================
--- testsuite/g++.dg/other/error10.C    (revision 186473)
+++ testsuite/g++.dg/other/error10.C    (working copy)
@@ -6,10 +6,9 @@ template<int> struct A {};
 
 template<int N>
 void foo(const A<N> &a)
-{ -A<N>(a); } // { dg-error "\\(\\* & a\\)" "" }
+{ -A<N>(a); } // { dg-error "operand type is 'A<0>'" }
 
 void bar()
 {
     foo(A<0>()); // { dg-message "required from here" "" }
 }
-
Index: testsuite/g++.dg/parse/error30.C
===================================================================
--- testsuite/g++.dg/parse/error30.C    (revision 186473)
+++ testsuite/g++.dg/parse/error30.C    (working copy)
@@ -8,5 +8,5 @@ struct A
   A(int);
 };
 
-A a = -A();    // { dg-error "10:no match for.*operator-.*in.*-A\\(\\)" }
-A b = -A(5);   // { dg-error "11:no match for.*operator-.*in.*-A\\(5\\)" }
+A a = -A();    // { dg-error "operand type is 'A'" }
+A b = -A(5);   // { dg-error "operand type is 'A'" }
Index: testsuite/g++.dg/cpp0x/lambda/lambda-err1.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-err1.C (revision 186473)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-err1.C (working copy)
@@ -4,5 +4,5 @@
 void foo()
 {
   int x[1];
-  [x]{} = 0;                   // { dg-error "lambda closure" }
+  [x]{} = 0;                   // { dg-error "lambda" }
 }
Index: cp/call.c
===================================================================
--- cp/call.c   (revision 186473)
+++ cp/call.c   (working copy)
@@ -4149,6 +4149,24 @@ build_op_call (tree obj, VEC(tree,gc) **args, tsub
   return ret;
 }
 
+static const char *
+op_error_string (const char *err_msg, int ntypes, bool match)
+{
+  const char *msg;
+
+  const char *msgt = concat (match ? G_("ambiguous overload for ")
+                                  : G_("no match for "), err_msg, NULL);
+
+  if (ntypes == 3)
+    msg = concat (msgt, G_(" (operand types are %qT, %qT, and %qT)"), NULL);
+  else if (ntypes == 2)
+    msg = concat (msgt, G_(" (operand types are %qT and %qT)"), NULL);
+  else
+    msg = concat (msgt, G_(" (operand type is %qT)"), NULL);
+
+  return msg;
+}
+
 static void
 op_error (enum tree_code code, enum tree_code code2,
          tree arg1, tree arg2, tree arg3, bool match)
@@ -4163,58 +4181,63 @@ op_error (enum tree_code code, enum tree_code code
   switch (code)
     {
     case COND_EXPR:
-      if (match)
-        error ("ambiguous overload for ternary %<operator?:%> "
-               "in %<%E ? %E : %E%>", arg1, arg2, arg3);
+      if (!flag_diagnostics_show_caret)
+       error (op_error_string (G_("ternary %<operator?:%> "
+                                  "in %<%E ? %E : %E%>"), 3, match),
+              arg1, arg2, arg3,
+              TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
       else
-        error ("no match for ternary %<operator?:%> "
-               "in %<%E ? %E : %E%>", arg1, arg2, arg3);
+       error (op_error_string (G_("ternary %<operator?:%>"), 3, match),
+              TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
       break;
 
     case POSTINCREMENT_EXPR:
     case POSTDECREMENT_EXPR:
-      if (match)
-        error ("ambiguous overload for %<operator%s%> in %<%E%s%>",
-               opname, arg1, opname);
+      if (!flag_diagnostics_show_caret)
+       error (op_error_string (G_("%<operator%s%> in %<%E%s%>"), 1, match),
+              opname, arg1, opname, TREE_TYPE (arg1));
       else
-        error ("no match for %<operator%s%> in %<%E%s%>", 
-               opname, arg1, opname);
+       error (op_error_string (G_("%<operator%s%>"), 1, match), opname,
+              TREE_TYPE (arg1));
       break;
 
     case ARRAY_REF:
-      if (match)
-        error ("ambiguous overload for %<operator[]%> in %<%E[%E]%>", 
-               arg1, arg2);
+      if (!flag_diagnostics_show_caret)
+       error (op_error_string (G_("%<operator[]%> in %<%E[%E]%>"), 2, match),
+              arg1, arg2, TREE_TYPE (arg1), TREE_TYPE (arg2));
       else
-        error ("no match for %<operator[]%> in %<%E[%E]%>", 
-               arg1, arg2);
+       error (op_error_string (G_("%<operator[]%>"), 2, match),
+              TREE_TYPE (arg1), TREE_TYPE (arg2));
       break;
 
     case REALPART_EXPR:
     case IMAGPART_EXPR:
-      if (match)
-        error ("ambiguous overload for %qs in %<%s %E%>", 
-               opname, opname, arg1);
+      if (!flag_diagnostics_show_caret)
+       error (op_error_string (G_("%qs in %<%s %E%>"), 1, match),
+              opname, opname, arg1, TREE_TYPE (arg1));
       else
-        error ("no match for %qs in %<%s %E%>",
-               opname, opname, arg1);
+       error (op_error_string (G_("%qs"), 1, match), opname,
+              TREE_TYPE (arg1));
       break;
 
     default:
       if (arg2)
-        if (match)
-          error ("ambiguous overload for %<operator%s%> in %<%E %s %E%>",
-                  opname, arg1, opname, arg2);
-        else
-          error ("no match for %<operator%s%> in %<%E %s %E%>",
-                 opname, arg1, opname, arg2);
+       if (!flag_diagnostics_show_caret)
+         error (op_error_string (G_("%<operator%s%> in %<%E %s %E%>"),
+                                 2, match),
+                opname, arg1, opname, arg2,
+                TREE_TYPE (arg1), TREE_TYPE (arg2));
+         else
+           error (op_error_string (G_("%<operator%s%>"), 2, match), opname,
+                  TREE_TYPE (arg1), TREE_TYPE (arg2));
       else
-        if (match)
-          error ("ambiguous overload for %<operator%s%> in %<%s%E%>",
-                 opname, opname, arg1);
-        else
-          error ("no match for %<operator%s%> in %<%s%E%>",
-                 opname, opname, arg1);
+       if (!flag_diagnostics_show_caret)
+         error (op_error_string (G_("%<operator%s%> in %<%s%E%>"),
+                                 1, match),
+                opname, opname, arg1, TREE_TYPE (arg1));
+       else
+         error (op_error_string (G_("%<operator%s%>"), 1, match),
+                opname, TREE_TYPE (arg1));
       break;
     }
 }

Reply via email to