Skip to content

Commit

Permalink
Raise error if cast has storage specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Jan 16, 2025
1 parent 61f4083 commit ca56944
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cc/frontend/parser_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }'
Expand Down

0 comments on commit ca56944

Please sign in to comment.