scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0e38613504c7711310c22403a692bef825f00dc8
parent 825d523e6ae30a93224c2d6799592ae73f7ea926
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  5 Aug 2014 18:20:31 +0200

Forbids castings to array or functions

These casting are explicitily forbidden in the standard, and
it has sense, since we can not change the type of an object
memory.

There is no legal use of a function type name, and it makes
ambigous the gramatic, because the parentheses can be nested
directdcl or a fundcl. So the simpler solution is to forbid
always the type names of functions.

Diffstat:
Mcc1/decl.c | 2++
Mcc1/expr.c | 2++
2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -500,6 +500,8 @@ typename(void) tp = specifier(&sclass); if (sclass) error("class storage in type name"); + if (yytoken == '(') + error("type name specifies a function type"); sym = declarator(tp, ID_FORBIDDEN); return sym->type; } diff --git a/cc1/expr.c b/cc1/expr.c @@ -551,6 +551,8 @@ cast2(void) case TQUALIFIER: case TYPE: tp = typename(); expect(')'); + if (tp->op == ARY) + error("cast specify an array type"); if ((np1 = eval(cast())) == NULL) unexpected(); if ((np2 = convert(np1, tp, 1)) == NULL)