diff --git a/src/cc/frontend/parser_expr.c b/src/cc/frontend/parser_expr.c index ba507aab7..bf6837576 100644 --- a/src/cc/frontend/parser_expr.c +++ b/src/cc/frontend/parser_expr.c @@ -1091,6 +1091,9 @@ static Expr *parse_cast_expr(void) { if (type != NULL) { // Cast consume(TK_RPAR, "`)' expected"); + if (storage & (VS_EXTERN | VS_STATIC | VS_TYPEDEF | VS_INLINE)) + parse_error(PE_NOFATAL, token, "storage specifier not allowed"); + Token *token2 = fetch_token(); if (token2->kind == TK_LBRACE) { Expr *complit = parse_compound_literal(type); diff --git a/tests/test.sh b/tests/test.sh index dbf74e53d..cb79b51cb 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -132,6 +132,8 @@ function test_error() { compile_error 'int*->' 'int main(){ int *p; p->x; }' compile_error 'void var' 'int main(){ void x; (void)x; }' compile_error 'void expr' 'int main(){ 1 + (void)2; }' + compile_error 'extern cast' 'int main(){ return (extern int)1; }' + compile_error 'static cast' 'int main(){ return (static int)1; }' compile_error 'empty char' "int main() { return ''; }" compile_error 'no single char' "int main() { return '12'; }" compile_error '+ str' 'int main(){ +"foo"; }'