This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: include types in invalid operand error messages
- From: "Daniel Berlin" <dberlin at dberlin dot org>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Cc: "Mark Mitchell" <mark at codesourcery dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Thu, 31 May 2007 10:08:51 -0400
- Subject: [PATCH]: include types in invalid operand error messages
This patch changes our error messages for dereferencing and binary
operators to include the types involved, which is much friendlier to
the user.
For:
int main(void)
{
struct foostruct
{
int a;
} foo;
int t, *q;
t + foo;
*t;
}
We used to print:
t.c: In function 'main':
t.c:8: error: invalid operands to binary +
t.c:9: error: invalid type argument of 'unary *'
With this patch, we print:
t.c:8: error: invalid operands to binary + (have 'int' and 'struct foostruct')
t.c:9: error: invalid type argument of 'unary *' (have 'int')
Because our regexps still match in the testsuite, this does not cause
any testsuite failures.
Bootstrapped and regtested on i686-darwin
Okay for mainline?
in gcc/
2007-05-31 Daniel Berlin <dberlin@dberlin.org>
* c-typeck.c (build_indirect_ref): Include type in error message.
(build_binary_op): Pass types to binary_op_error.
* c-common.c (binary_op_error): Take two type arguments, print out
types with error.
* c-common.h (binary_op_error): Update prototype.
in gcc/cp
2007-05-31 Daniel Berlin <dberlin@dberlin.org>
* typeck.c (build_binary_op): Include types in error.
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 125030)
+++ cp/typeck.c (working copy)
@@ -3552,7 +3552,7 @@ build_binary_op (enum tree_code code, tr
|| !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
TREE_TYPE (type1)))
{
- binary_op_error (code);
+ binary_op_error (code, type0, type1);
return error_mark_node;
}
arithmetic_types_p = 1;
Index: c-typeck.c
===================================================================
--- c-typeck.c (revision 125030)
+++ c-typeck.c (working copy)
@@ -1923,7 +1923,7 @@ build_indirect_ref (tree ptr, const char
}
}
else if (TREE_CODE (pointer) != ERROR_MARK)
- error ("invalid type argument of %qs", errorstring);
+ error ("invalid type argument of %qs (have %qT)", errorstring, type);
return error_mark_node;
}
@@ -8135,7 +8135,7 @@ build_binary_op (enum tree_code code, tr
|| !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
TREE_TYPE (type1))))
{
- binary_op_error (code);
+ binary_op_error (code, type0, type1);
return error_mark_node;
}
@@ -8435,7 +8435,7 @@ build_binary_op (enum tree_code code, tr
if (!result_type)
{
- binary_op_error (code);
+ binary_op_error (code, TREE_TYPE (op0), TREE_TYPE (op1));
return error_mark_node;
}
Index: c-common.c
===================================================================
--- c-common.c (revision 125030)
+++ c-common.c (working copy)
@@ -2230,10 +2230,10 @@ min_precision (tree value, int unsignedp
}
/* Print an error message for invalid operands to arith operation
- CODE. */
+ CODE with TYPE0 for operand 0, and TYPE1 for operand 1. */
void
-binary_op_error (enum tree_code code)
+binary_op_error (enum tree_code code, tree type0, tree type1)
{
const char *opname;
@@ -2284,7 +2284,8 @@ binary_op_error (enum tree_code code)
default:
gcc_unreachable ();
}
- error ("invalid operands to binary %s", opname);
+ error ("invalid operands to binary %s (have %qT and %qT)", opname,
+ type0, type1);
}
/* Subroutine of build_binary_op, used for comparison operations.
Index: c-common.h
===================================================================
--- c-common.h (revision 125030)
+++ c-common.h (working copy)
@@ -677,7 +677,7 @@ extern tree c_sizeof_or_alignof_type (tr
extern tree c_alignof_expr (tree);
/* Print an error message for invalid operands to arith operation CODE.
NOP_EXPR is used as a special case (see truthvalue_conversion). */
-extern void binary_op_error (enum tree_code);
+extern void binary_op_error (enum tree_code, tree, tree);
extern tree fix_string_type (tree);
struct varray_head_tag;
extern void constant_expression_warning (tree);