From 5fe4480b0ecf7a26724ce8ae8817a30fd43afb5a Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sun, 29 Sep 2019 15:05:41 +0700 Subject: [PATCH 1/2] Ignore state specifications on old-style forward declarations --- source/compiler/sc1.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 85dafe7..143bf28 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3246,8 +3246,6 @@ static int getstates(const char *funcname) static void attachstatelist(symbol *sym, int state_id) { assert(sym!=NULL); - if ((sym->usage & uDEFINE)!=0 && (sym->states==NULL || state_id==0)) - error(21,sym->name); /* function already defined, either without states or the current definition has no states */ if (state_id!=0) { /* add the state list id */ @@ -3947,7 +3945,6 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc state_id=getstates(symbolname); if (state_id>0 && (opertok!=0 || strcmp(symbolname,uMAINFUNC)==0)) error(82); /* operators may not have states, main() may neither */ - attachstatelist(sym,state_id); pc_deprecate=bck_deprecate; pc_attributes=bck_attributes; if (matchtoken(t__PRAGMA)) @@ -3959,9 +3956,12 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc sym->usage|=uFORWARD; if (!sc_needsemicolon) error(218); /* old style prototypes used with optional semicolons */ + if (state_id!=0) + error(231); /* state specification on forward declaration is ignored */ delete_symbols(&loctab,0,TRUE,TRUE); /* prototype is done; forget everything */ return TRUE; } /* if */ + attachstatelist(sym,state_id); /* so it is not a prototype, proceed */ /* if this is a function that is not referred to (this can only be detected * in the second stage), shut code generation off */ @@ -3970,6 +3970,8 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc cidx=code_idx; glbdecl=glb_declared; } /* if */ + if ((sym->usage & uDEFINE)!=0 && (sym->states==NULL || state_id==0)) + error(21,sym->name); /* function already defined, either without states or the current definition has no states */ if ((sym->flags & flagDEPRECATED)!=0 && fpublic) { char *ptr= (sym->documentation!=NULL) ? sym->documentation : ""; error(234,symbolname,ptr); /* deprecated (definitely a public function) */ From c9d2acb605666c0da378defb0a2f064c72e18bd7 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 8 Jan 2021 18:23:28 +0700 Subject: [PATCH 2/2] Add tests --- source/compiler/tests/warning_231.meta | 7 +++++++ source/compiler/tests/warning_231.pwn | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 source/compiler/tests/warning_231.meta create mode 100644 source/compiler/tests/warning_231.pwn diff --git a/source/compiler/tests/warning_231.meta b/source/compiler/tests/warning_231.meta new file mode 100644 index 0000000..1e107c3 --- /dev/null +++ b/source/compiler/tests/warning_231.meta @@ -0,0 +1,7 @@ +{ + 'test_type': 'output_check', + 'errors': """ +warning_231.pwn(3) : warning 231: state specification on forward declaration is ignored +warning_231.pwn(6) : warning 231: state specification on forward declaration is ignored +""" +} diff --git a/source/compiler/tests/warning_231.pwn b/source/compiler/tests/warning_231.pwn new file mode 100644 index 0000000..1df19a1 --- /dev/null +++ b/source/compiler/tests/warning_231.pwn @@ -0,0 +1,9 @@ +#pragma option -;+ + +forward Func() ; // warning 231: state specification on forward declaration is ignored +public Func() {} + +public Func() ; // warning 231: state specification on forward declaration is ignored +public Func() {} + +main(){}