summaryrefslogtreecommitdiffstats
path: root/gcc/c-typeck.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r--gcc/c-typeck.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index a89c87a3601..9ddafe10c5d 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2561,6 +2561,8 @@ build_unary_op (enum tree_code code, tree xarg, int flag)
break;
case TRUTH_NOT_EXPR:
+ /* ??? Why do most validation here but that for non-lvalue arrays
+ in c_objc_common_truthvalue_conversion? */
if (typecode != INTEGER_TYPE
&& typecode != REAL_TYPE && typecode != POINTER_TYPE
&& typecode != COMPLEX_TYPE
@@ -2570,7 +2572,7 @@ build_unary_op (enum tree_code code, tree xarg, int flag)
error ("wrong type argument to unary exclamation mark");
return error_mark_node;
}
- arg = lang_hooks.truthvalue_conversion (arg);
+ arg = c_objc_common_truthvalue_conversion (arg);
return invert_truthvalue (arg);
case NOP_EXPR:
@@ -2926,8 +2928,6 @@ build_conditional_expr (tree ifexp, tree op1, tree op2)
tree result_type = NULL;
tree orig_op1 = op1, orig_op2 = op2;
- ifexp = lang_hooks.truthvalue_conversion (default_conversion (ifexp));
-
/* Promote both alternatives. */
if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
@@ -7316,8 +7316,8 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
but that does not mean the operands should be
converted to ints! */
result_type = integer_type_node;
- op0 = lang_hooks.truthvalue_conversion (op0);
- op1 = lang_hooks.truthvalue_conversion (op1);
+ op0 = c_common_truthvalue_conversion (op0);
+ op1 = c_common_truthvalue_conversion (op1);
converted = 1;
}
break;
@@ -7797,3 +7797,34 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
return result;
}
}
+
+
+/* Convert EXPR to be a truth-value, validating its type for this
+ purpose. Passes EXPR to default_function_array_conversion. */
+
+tree
+c_objc_common_truthvalue_conversion (tree expr)
+{
+ expr = default_function_array_conversion (expr);
+ switch (TREE_CODE (TREE_TYPE (expr)))
+ {
+ case ARRAY_TYPE:
+ error ("used array that cannot be converted to pointer where scalar is required");
+ return error_mark_node;
+
+ case RECORD_TYPE:
+ error ("used struct type value where scalar is required");
+ return error_mark_node;
+
+ case UNION_TYPE:
+ error ("used union type value where scalar is required");
+ return error_mark_node;
+
+ default:
+ break;
+ }
+
+ /* ??? Should we also give an error for void and vectors rather than
+ leaving those to give errors later? */
+ return c_common_truthvalue_conversion (expr);
+}
OpenPOWER on IntegriCloud