From: paolo Date: Mon, 16 Apr 2012 15:32:22 +0000 (+0000) Subject: /cp X-Git-Tag: upstream/4.9.2~13243 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c9c9381f59fa9e2b86019b27aad5f6737fbd682;p=platform%2Fupstream%2Flinaro-gcc.git /cp 2012-04-16 Paolo Carlini 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 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186499 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5a3d337..71cf71c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2012-04-16 Paolo Carlini + + PR c++/49152 + * call.c (op_error): Print types; when flag_diagnostics_show_caret + is false print expressions too. + (op_error_string): Add. + 2012-04-16 Jason Merrill PR c++/51148 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 46ac55c..06a1225 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4149,6 +4149,28 @@ build_op_call (tree obj, VEC(tree,gc) **args, tsubst_flags_t complain) return ret; } +/* Called by op_error to prepare format strings suitable for the error + function. It concatenates a prefix (controlled by MATCH), ERRMSG, + and a suffix (controlled by NTYPES). */ + +static const char * +op_error_string (const char *errmsg, int ntypes, bool match) +{ + const char *msg; + + const char *msgp = concat (match ? G_("ambiguous overload for ") + : G_("no match for "), errmsg, NULL); + + if (ntypes == 3) + msg = concat (msgp, G_(" (operand types are %qT, %qT, and %qT)"), NULL); + else if (ntypes == 2) + msg = concat (msgp, G_(" (operand types are %qT and %qT)"), NULL); + else + msg = concat (msgp, 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 +4185,63 @@ op_error (enum tree_code code, enum tree_code code2, switch (code) { case COND_EXPR: - if (match) - error ("ambiguous overload for ternary % " - "in %<%E ? %E : %E%>", arg1, arg2, arg3); + if (flag_diagnostics_show_caret) + error (op_error_string (G_("ternary %"), 3, match), + TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3)); else - error ("no match for ternary % " - "in %<%E ? %E : %E%>", arg1, arg2, arg3); + error (op_error_string (G_("ternary % " + "in %<%E ? %E : %E%>"), 3, match), + arg1, arg2, arg3, + TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3)); break; case POSTINCREMENT_EXPR: case POSTDECREMENT_EXPR: - if (match) - error ("ambiguous overload for % in %<%E%s%>", - opname, arg1, opname); + if (flag_diagnostics_show_caret) + error (op_error_string (G_("%"), 1, match), + opname, TREE_TYPE (arg1)); else - error ("no match for % in %<%E%s%>", - opname, arg1, opname); + error (op_error_string (G_("% in %<%E%s%>"), 1, match), + opname, arg1, opname, TREE_TYPE (arg1)); break; case ARRAY_REF: - if (match) - error ("ambiguous overload for % in %<%E[%E]%>", - arg1, arg2); + if (flag_diagnostics_show_caret) + error (op_error_string (G_("%"), 2, match), + TREE_TYPE (arg1), TREE_TYPE (arg2)); else - error ("no match for % in %<%E[%E]%>", - arg1, arg2); + error (op_error_string (G_("% in %<%E[%E]%>"), 2, match), + arg1, arg2, 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"), 1, match), + opname, TREE_TYPE (arg1)); else - error ("no match for %qs in %<%s %E%>", - opname, opname, arg1); + error (op_error_string (G_("%qs in %<%s %E%>"), 1, match), + opname, opname, arg1, TREE_TYPE (arg1)); break; default: if (arg2) - if (match) - error ("ambiguous overload for % in %<%E %s %E%>", - opname, arg1, opname, arg2); - else - error ("no match for % in %<%E %s %E%>", - opname, arg1, opname, arg2); + if (flag_diagnostics_show_caret) + error (op_error_string (G_("%"), 2, match), + opname, TREE_TYPE (arg1), TREE_TYPE (arg2)); + else + error (op_error_string (G_("% in %<%E %s %E%>"), + 2, match), + opname, arg1, opname, arg2, + TREE_TYPE (arg1), TREE_TYPE (arg2)); else - if (match) - error ("ambiguous overload for % in %<%s%E%>", - opname, opname, arg1); - else - error ("no match for % in %<%s%E%>", - opname, opname, arg1); + if (flag_diagnostics_show_caret) + error (op_error_string (G_("%"), 1, match), + opname, TREE_TYPE (arg1)); + else + error (op_error_string (G_("% in %<%s%E%>"), + 1, match), + opname, opname, arg1, TREE_TYPE (arg1)); break; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 27df0fb..1f70676 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2012-04-16 Paolo Carlini + + 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. + 2012-04-16 Jason Merrill PR c++/51148 diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-err1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-err1.C index ebf0cbd..932ff1b 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-err1.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-err1.C @@ -4,5 +4,5 @@ void foo() { int x[1]; - [x]{} = 0; // { dg-error "lambda closure" } + [x]{} = 0; // { dg-error "lambda" } } diff --git a/gcc/testsuite/g++.dg/ext/label5.C b/gcc/testsuite/g++.dg/ext/label5.C index fc611cd..34ca90d 100644 --- a/gcc/testsuite/g++.dg/ext/label5.C +++ b/gcc/testsuite/g++.dg/ext/label5.C @@ -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 } diff --git a/gcc/testsuite/g++.dg/ext/va-arg1.C b/gcc/testsuite/g++.dg/ext/va-arg1.C index 079db2e..5606128 100644 --- a/gcc/testsuite/g++.dg/ext/va-arg1.C +++ b/gcc/testsuite/g++.dg/ext/va-arg1.C @@ -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'" } } diff --git a/gcc/testsuite/g++.dg/other/error10.C b/gcc/testsuite/g++.dg/other/error10.C index 5c17277..546a4d6 100644 --- a/gcc/testsuite/g++.dg/other/error10.C +++ b/gcc/testsuite/g++.dg/other/error10.C @@ -6,10 +6,9 @@ template struct A {}; template void foo(const A &a) -{ -A(a); } // { dg-error "\\(\\* & a\\)" "" } +{ -A(a); } // { dg-error "operand type is 'A<0>'" } void bar() { foo(A<0>()); // { dg-message "required from here" "" } } - diff --git a/gcc/testsuite/g++.dg/other/error16.C b/gcc/testsuite/g++.dg/other/error16.C index 1e34647..38c0fd6 100644 --- a/gcc/testsuite/g++.dg/other/error16.C +++ b/gcc/testsuite/g++.dg/other/error16.C @@ -10,5 +10,5 @@ typedef Outer XOuter; int main() { Outer ab; - ab.foo() == 1; // { dg-error "ab.Outer" } + ab.foo() == 1; // { dg-error "operand types are 'Outer::Inner' and 'int'" } } diff --git a/gcc/testsuite/g++.dg/other/error20.C b/gcc/testsuite/g++.dg/other/error20.C index f3b17aa1..bb7d7b3 100644 --- a/gcc/testsuite/g++.dg/other/error20.C +++ b/gcc/testsuite/g++.dg/other/error20.C @@ -8,6 +8,6 @@ struct A // { dg-message "operator=|no known conversion" } 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 } } diff --git a/gcc/testsuite/g++.dg/parse/error30.C b/gcc/testsuite/g++.dg/parse/error30.C index 26c55c4..aabdcc7 100644 --- a/gcc/testsuite/g++.dg/parse/error30.C +++ b/gcc/testsuite/g++.dg/parse/error30.C @@ -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'" }