Skip to content

Commit a154378

Browse files
committed
Fix Extern Byref declarations to not require initializer
It should be possible to declare extern references, and like any other externs, they are not initialized at the Extern, but at the corresponding Dim (if any). http://www.freebasic.net/forum/viewtopic.php?p=211604#p211604
1 parent 959e586 commit a154378

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/compiler/parser-decl-var.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,8 +1710,8 @@ function cVarDecl _
17101710
else
17111711
'' default initialization
17121712
if( sym ) then
1713-
'' Byref? Always requires an explicit initializer
1714-
if( symbIsRef( sym ) ) then
1713+
'' Allocating a Byref variable? Always requires an explicit initializer
1714+
if( (not symbIsExtern( sym )) and symbIsRef( sym ) ) then
17151715
errReport( FB_ERRMSG_MISSINGREFINIT )
17161716
hSkipStmt( )
17171717
exit function

tests/dim/byref-common.bi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace fbc_tests.dim_.byref_
2+
namespace externs
3+
extern i as integer
4+
extern byref ri as integer
5+
type SomeUDT
6+
dummy as integer
7+
static i as integer
8+
static byref ri as integer
9+
end type
10+
end namespace
11+
end namespace

tests/dim/byref.bas

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "fbcu.bi"
2+
#include "byref-common.bi"
23

34
namespace fbc_tests.dim_.byref_
45

@@ -583,13 +584,25 @@ namespace privateDtor
583584
end sub
584585
end namespace
585586

587+
namespace externs
588+
sub test cdecl( )
589+
CU_ASSERT( @ri = @i )
590+
CU_ASSERT( @SomeUDT.ri = @SomeUDT.i )
591+
CU_ASSERT( i = &hEE112233 )
592+
CU_ASSERT( ri = &hEE112233 )
593+
CU_ASSERT( SomeUDT.i = &hEE445566 )
594+
CU_ASSERT( SomeUDT.ri = &hEE445566 )
595+
end sub
596+
end namespace
597+
586598
private sub ctor( ) constructor
587599
fbcu.add_suite( "tests/dim/byref" )
588600
fbcu.add_test( "simpleVars", @simpleVars.test )
589601
fbcu.add_test( "allDtypes", @allDtypes.test )
590602
fbcu.add_test( "callByrefFunctionPtrThroughByref", @callByrefFunctionPtrThroughByref.test )
591603
fbcu.add_test( "noCtorsCalled", @noCtorsCalled.test )
592604
fbcu.add_test( "privateDtor", @privateDtor.test )
605+
fbcu.add_test( "externs", @externs.test )
593606
end sub
594607

595608
end namespace

tests/dim/byref2.bas

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "fbcu.bi"
2+
#include "byref-common.bi"
3+
4+
namespace fbc_tests.dim_.byref_
5+
namespace externs
6+
dim shared i as integer = &hEE112233
7+
dim shared byref ri as integer = i
8+
dim shared SomeUDT.i as integer = &hEE445566
9+
dim shared byref SomeUDT.ri as integer = SomeUDT.i
10+
end namespace
11+
end namespace

0 commit comments

Comments
 (0)