mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-21 07:30:53 +00:00
Don't allow a stale 'some_type;' declaration without an actual variable name; Same for typedef; closes #119
This commit is contained in:
parent
2ff9adecb2
commit
702a7664de
1 changed files with 20 additions and 0 deletions
20
parser.c
20
parser.c
|
@ -4658,6 +4658,11 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
|
|||
* The base type makes up every bit of type information which comes *before* the
|
||||
* variable name.
|
||||
*
|
||||
* NOTE: The value must either be named, have a NULL name, or a name starting
|
||||
* with '<'. In the first case, this will be the actual variable or type
|
||||
* name, in the other cases it is assumed that the name will appear
|
||||
* later, and an error is generated otherwise.
|
||||
*
|
||||
* The following will be parsed in its entirety:
|
||||
* void() foo()
|
||||
* The 'basetype' in this case is 'void()'
|
||||
|
@ -4818,6 +4823,13 @@ static bool parse_typedef(parser_t *parser)
|
|||
if (!typevar)
|
||||
return false;
|
||||
|
||||
/* while parsing types, the ast_value's get named '<something>' */
|
||||
if (!typevar->name || typevar->name[0] == '<') {
|
||||
parseerror(parser, "missing name in typedef");
|
||||
ast_delete(typevar);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( (old = parser_find_var(parser, typevar->name)) ) {
|
||||
parseerror(parser, "cannot define a type with the same name as a variable: %s\n"
|
||||
" -> `%s` has been declared here: %s:%i",
|
||||
|
@ -4983,6 +4995,14 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
|
|||
return false;
|
||||
}
|
||||
|
||||
/* while parsing types, the ast_value's get named '<something>' */
|
||||
if (!var->name || var->name[0] == '<') {
|
||||
parseerror(parser, "declaration does not declare anything");
|
||||
if (basetype)
|
||||
ast_delete(basetype);
|
||||
return false;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
proto = NULL;
|
||||
wasarray = false;
|
||||
|
|
Loading…
Reference in a new issue