Add some tests and errors for bad void usage.
This commit is contained in:
parent
dfa9a8f134
commit
1c41f905f9
@ -154,6 +154,7 @@ static void inst_binary_name(char *binfname);
|
|||||||
static int operatorname(char *name);
|
static int operatorname(char *name);
|
||||||
static int reparse_old_decl(declinfo_t *decl, int flags);
|
static int reparse_old_decl(declinfo_t *decl, int flags);
|
||||||
static int reparse_new_decl(declinfo_t *decl, int flags);
|
static int reparse_new_decl(declinfo_t *decl, int flags);
|
||||||
|
static void check_void_decl(const declinfo_t *decl, int variable);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TEST_PLAIN, /* no parentheses */
|
TEST_PLAIN, /* no parentheses */
|
||||||
@ -1978,6 +1979,8 @@ static void declglb(declinfo_t *decl,int fpublic,int fstatic,int fstock)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
typeinfo_t *type = &decl->type;
|
typeinfo_t *type = &decl->type;
|
||||||
|
|
||||||
|
check_void_decl(decl, TRUE);
|
||||||
|
|
||||||
ispublic=fpublic;
|
ispublic=fpublic;
|
||||||
if (decl->name[0]==PUBLIC_CHAR) {
|
if (decl->name[0]==PUBLIC_CHAR) {
|
||||||
ispublic=TRUE; /* implicitly public variable */
|
ispublic=TRUE; /* implicitly public variable */
|
||||||
@ -3429,7 +3432,23 @@ int parse_decl(declinfo_t *decl, int flags)
|
|||||||
return parse_new_decl(decl, NULL, flags);
|
return parse_new_decl(decl, NULL, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void define_constructor(methodmap_t *map, methodmap_method_t *method)
|
static void check_void_decl(const declinfo_t *decl, int variable)
|
||||||
|
{
|
||||||
|
if (decl->type.tag != pc_tag_void)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (variable) {
|
||||||
|
error(144);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (decl->type.numdim > 0) {
|
||||||
|
error(145);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void define_constructor(methodmap_t *map, methodmap_method_t *method)
|
||||||
{
|
{
|
||||||
symbol *sym = findglb(map->name, sGLOBAL);
|
symbol *sym = findglb(map->name, sGLOBAL);
|
||||||
|
|
||||||
@ -4970,9 +4989,12 @@ static int newfunc(declinfo_t *decl, const int *thistag, int fpublic, int fstati
|
|||||||
if (symp)
|
if (symp)
|
||||||
*symp = NULL;
|
*symp = NULL;
|
||||||
|
|
||||||
|
check_void_decl(decl, FALSE);
|
||||||
|
|
||||||
if (decl->opertok) {
|
if (decl->opertok) {
|
||||||
check_operatortag(decl->opertok, decl->type.tag, decl->name);
|
check_operatortag(decl->opertok, decl->type.tag, decl->name);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* check whether this is a function or a variable declaration */
|
/* check whether this is a function or a variable declaration */
|
||||||
if (!matchtoken('('))
|
if (!matchtoken('('))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -5266,9 +5288,12 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag)
|
|||||||
if (!matchtoken(')')){
|
if (!matchtoken(')')){
|
||||||
do { /* there are arguments; process them */
|
do { /* there are arguments; process them */
|
||||||
declinfo_t decl;
|
declinfo_t decl;
|
||||||
|
|
||||||
parse_decl(&decl, DECLFLAG_ARGUMENT|DECLFLAG_ENUMROOT);
|
parse_decl(&decl, DECLFLAG_ARGUMENT|DECLFLAG_ENUMROOT);
|
||||||
assert(decl.type.numtags > 0);
|
assert(decl.type.numtags > 0);
|
||||||
|
|
||||||
|
check_void_decl(&decl, TRUE);
|
||||||
|
|
||||||
if (decl.type.ident == iVARARGS) {
|
if (decl.type.ident == iVARARGS) {
|
||||||
assert(decl.type.numtags > 0);
|
assert(decl.type.numtags > 0);
|
||||||
if ((sym->usage & uPROTOTYPED)==0) {
|
if ((sym->usage & uPROTOTYPED)==0) {
|
||||||
|
@ -187,6 +187,8 @@ static char *errmsg[] = {
|
|||||||
/*141*/ "natives, forwards, and public functions cannot return arrays\n",
|
/*141*/ "natives, forwards, and public functions cannot return arrays\n",
|
||||||
/*142*/ "invalid type declaration\n",
|
/*142*/ "invalid type declaration\n",
|
||||||
/*143*/ "new-style declarations should not have \"new\"\n",
|
/*143*/ "new-style declarations should not have \"new\"\n",
|
||||||
|
/*144*/ "void cannot be used as a variable type\n",
|
||||||
|
/*145*/ "invalid type expression\n",
|
||||||
#else
|
#else
|
||||||
"\250\261\311\232\271k\214:\234\303bu\201fo\223\204\221\012",
|
"\250\261\311\232\271k\214:\234\303bu\201fo\223\204\221\012",
|
||||||
"\202l\224\252s\205g\353\350e\233\201(\243\250\327\274\202) \255 f\247low ea\300 \042c\343e\042\012",
|
"\202l\224\252s\205g\353\350e\233\201(\243\250\327\274\202) \255 f\247low ea\300 \042c\343e\042\012",
|
||||||
|
13
sourcepawn/compiler/tests/fail-bad-void.sp
Normal file
13
sourcepawn/compiler/tests/fail-bad-void.sp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
void[] Bad1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bad2;
|
||||||
|
|
||||||
|
stock Bad3(void x)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public main()
|
||||||
|
{
|
||||||
|
}
|
3
sourcepawn/compiler/tests/fail-bad-void.txt
Normal file
3
sourcepawn/compiler/tests/fail-bad-void.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(1) : error 145: invalid type expression
|
||||||
|
(5) : error 144: void cannot be used as a variable type
|
||||||
|
(7) : error 144: void cannot be used as a variable type
|
Loading…
Reference in New Issue
Block a user