[PATCH 1/2] display extra info for type errors in compare & conditional

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For "incompatible types in comparison expression" errors, only the
kind of type difference is displayed. Displaying the types would
make eaiser to find the cause of the problem. The same is true
for ternary conditionals.

So, also display the left & right types.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 evaluate.c                   | 8 ++++++--
 validation/cond-err-expand.c | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index 947b121f4..efe6d28b8 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1132,7 +1132,9 @@ static struct symbol *evaluate_compare(struct expression *expr)
 	if (!typediff)
 		goto OK;
 
-	expression_error(expr, "incompatible types in comparison expression (%s)", typediff);
+	expression_error(expr, "incompatible types in comparison expression (%s):", typediff);
+	info(expr->pos, "   %s", show_typename(ltype));
+	info(expr->pos, "   %s", show_typename(rtype));
 	return NULL;
 
 OK:
@@ -1268,7 +1270,9 @@ static struct symbol *evaluate_conditional_expression(struct expression *expr)
 	typediff = "different base types";
 
 Err:
-	expression_error(expr, "incompatible types in conditional expression (%s)", typediff);
+	expression_error(expr, "incompatible types in conditional expression (%s):", typediff);
+	info(expr->pos, "   %s", show_typename(ltype));
+	info(expr->pos, "   %s", show_typename(rtype));
 	/*
 	 * if the condition is constant, the type is in fact known
 	 * so use it, as gcc & clang do.
diff --git a/validation/cond-err-expand.c b/validation/cond-err-expand.c
index 7936a2d00..b52624bc9 100644
--- a/validation/cond-err-expand.c
+++ b/validation/cond-err-expand.c
@@ -18,8 +18,12 @@ void bar(void)
  * check-command: test-linearize -Wno-decl $file
  *
  * check-error-start
-cond-err-expand.c:8:11: error: incompatible types in conditional expression (different base types)
-cond-err-expand.c:13:11: error: incompatible types in conditional expression (different base types)
+cond-err-expand.c:8:11: error: incompatible types in conditional expression (different base types):
+cond-err-expand.c:8:11:    int
+cond-err-expand.c:8:11:    void
+cond-err-expand.c:13:11: error: incompatible types in conditional expression (different base types):
+cond-err-expand.c:13:11:    void
+cond-err-expand.c:13:11:    int
  * check-error-end
  *
  * check-output-ignore
-- 
2.20.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux