ref: a100cd930fb84e4e0e1d3dc3c24d3bddd28eb4f0
parent: 2ea4d1165e7bd877f2e4e0f5b3ba16d727cce808
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Aug 11 19:22:52 EDT 2014
Fix tests of unary '-' and '+' These operator only can be applied to numerical types, but the code restricted them only to integers operators. Also in the case of + no new code must be generated, it is only a nop operator.
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -91,6 +91,18 @@
}
static Node *
+numericaluop(char op, Node *np)
+{
+ np = eval(np);
+ switch (np->typeop) {
+ case INT: case FLOAT:
+ return (op == OADD) ? np : unarycode(op, np->type, np);
+ default:
+ error("unary operator requires integer operand");
+ }
+}
+
+static Node *
integeruop(char op, Node *np)
{
np = eval(np);
@@ -534,9 +546,8 @@
next();
return incdec(unary(), op);
case '!': op = 0; fun = negation; break;
- /* FIXME: '-' and '+' can be applied to floats to */
- case '+': op = OADD; fun = integeruop; break;
- case '-': op = ONEG; fun = integeruop; break;
+ case '+': op = OADD; fun = numericaluop; break;
+ case '-': op = ONEG; fun = numericaluop; break;
case '~': op = OCPL; fun = integeruop; break;
case '&': op = OADDR; fun = address; break;
case '*': op = OPTR; fun = content; break;
--
⑨