scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit ab23974dffb7d6b6b73d65ef7c566e8b6abbd76b
parent 15cfc88a6819c09e4c93054b31c0be4d48b0aeb0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  5 Jul 2013 09:36:38 +0200

Forbid const or volatile in typedef

const or volatile are util only in variable declaration, and can
cause some problems in typedef declarations.

Diffstat:
types.c | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/types.c b/types.c @@ -172,6 +172,8 @@ storage(register struct ctype *tp, unsigned char mod) goto duplicated; if (tp->c_extern | tp->c_auto | tp->c_reg | tp->c_static) goto two_storage; + if (tp->c_const || tp->c_volatile) + goto bad_typedef; tp->c_typedef = 1; return tp; case EXTERN: @@ -209,14 +211,20 @@ storage(register struct ctype *tp, unsigned char mod) case CONST: if (options.repeat && tp->c_const) goto duplicated; + if (tp->c_typedef) + goto bad_typedef; tp->c_const = 1; return tp; case VOLATILE: if (options.repeat && tp->c_volatile) goto duplicated; + if (tp->c_typedef) + goto bad_typedef; tp->c_volatile = 1; return tp; } +bad_typedef: + error("typedef specifies type qualifier"); bad_file_scope_storage: error("file-scope declaration specifies '%s'", yytext); two_storage: