Skip to content

Commit

Permalink
parser: Disallow module ctor/dtor with private/protected visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dkl committed Apr 24, 2014
1 parent 43c046b commit 80b4c55
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion changelog.txt
Expand Up @@ -160,7 +160,7 @@ Version 0.91.0:
- #582: Wrong code generated for bitfield self-BOPs or SWAPs sometimes under -exx or if the bitfield expression contained function calls (side-effects)
- When specifying an .o file name without extension but '.' in its path (for example: -o ../foo), fbc created temporary files by stripping everything from the .o path until that '.' and then appending the new extension, which often resulted in bad/unexpected file names (for example: ..foo.asm).
- Calling getkey() in one thread won't cause other threads' rtlib function calls to block until getkey() returns anymore
- #726: CONSTRUCTOR|DESTRUCTOR (module-level initialization/cleanup) was allowed to be specified on sub prototypes (although, it was ignored) and method bodies (silently miscompiled due to the missing THIS argument). Now both these cases are disallowed, as neither makes sense.
- #726: CONSTRUCTOR|DESTRUCTOR (module-level initialization/cleanup) was allowed to be specified on sub prototypes (although, it was ignored), method bodies (silently miscompiled due to the missing THIS argument), and PRIVATE/PROTECTED static member procedures. Now these cases are disallowed.


Version 0.90.1:
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/parser-proc.bas
Expand Up @@ -1632,9 +1632,15 @@ function cProcHeader _

'' Register global ctors/dtors
if( stats and FB_SYMBSTATS_GLOBALCTOR ) then
if( proc->attrib and (FB_SYMBATTRIB_VIS_PRIVATE or FB_SYMBATTRIB_VIS_PROTECTED) ) then
errReport( FB_ERRMSG_NOACCESSTOCTOR, TRUE )
end if
symbAddGlobalCtor( proc )
symbSetProcPriority( proc, priority )
elseif( stats and FB_SYMBSTATS_GLOBALDTOR ) then
if( proc->attrib and (FB_SYMBATTRIB_VIS_PRIVATE or FB_SYMBATTRIB_VIS_PROTECTED) ) then
errReport( FB_ERRMSG_NOACCESSTODTOR, TRUE )
end if
symbAddGlobalDtor( proc )
symbSetProcPriority( proc, priority )
end if
Expand Down
11 changes: 11 additions & 0 deletions tests/visibility/private-module-ctor.bas
@@ -0,0 +1,11 @@
' TEST_MODE : COMPILE_ONLY_FAIL

type UDT
i as integer

private:
declare static sub ctor( )
end type

sub UDT.ctor( ) constructor
end sub
11 changes: 11 additions & 0 deletions tests/visibility/private-module-dtor.bas
@@ -0,0 +1,11 @@
' TEST_MODE : COMPILE_ONLY_FAIL

type UDT
i as integer

private:
declare static sub dtor( )
end type

sub UDT.dtor( ) destructor
end sub
11 changes: 11 additions & 0 deletions tests/visibility/protected-module-ctor.bas
@@ -0,0 +1,11 @@
' TEST_MODE : COMPILE_ONLY_FAIL

type UDT
i as integer

protected:
declare static sub ctor( )
end type

sub UDT.ctor( ) constructor
end sub
11 changes: 11 additions & 0 deletions tests/visibility/protected-module-dtor.bas
@@ -0,0 +1,11 @@
' TEST_MODE : COMPILE_ONLY_FAIL

type UDT
i as integer

protected:
declare static sub dtor( )
end type

sub UDT.dtor( ) destructor
end sub

0 comments on commit 80b4c55

Please sign in to comment.