aboutsummaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index c4974b8..48053c4 100644
--- a/eval.c
+++ b/eval.c
@@ -137,8 +137,15 @@ eval(struct expr *expr, enum evalkind kind)
else
expr->constant = l->constant;
cast(expr);
- } else if (l->type->kind == TYPEPOINTER && expr->type->kind == TYPEPOINTER) {
- expr = l;
+ } else if (l->type->kind == TYPEPOINTER) {
+ /*
+ A cast from a pointer to integer is not a valid constant
+ expression, but C11 allows implementations to recognize
+ other forms of constant expressions (6.6p10), and some
+ programs expect this functionality.
+ */
+ if (expr->type->kind == TYPEPOINTER || expr->type->prop & PROPINT && expr->type->size == typelong.size)
+ expr = l;
}
break;
case EXPRBINARY: