Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove debug code from Base() parsing, add another test, and update c…

…hangelog
  • Loading branch information...
commit e140c37e849c14c3dae425bc0c25080574799acc 1 parent 4350b47
@dkl dkl authored
View
3  changelog.txt
@@ -148,6 +148,9 @@ Version 0.24.0:
- #3490779: -exx and -profile broke Naked procedures due to implicit RTL calls; now no more implicit code will be added (this change affects error handling/profiling calls for naked procedures, and member constructor/destructor calls in naked constructors/destructors)
- Compiler crash on naked constructors/destructors
- Early return from an UDT destructor prevented destruction of the UDT's fields
+- #3489950: BASE() disabled implicit field construction and vtbl pointer setup in constructors
+- #3479349: No error was shown when a constructor couldn't initialize the base UDT (i.e. when the base UDT didn't have a default constructor and there was no BASE() used either)
+- #3479355: POD base UDTs weren't cleared by constructors
Version 0.23.0:
View
38 compiler/parser-proccall.bas
@@ -995,33 +995,31 @@ private sub hBaseInit( )
'' BASE
lexSkipToken( )
- '' Has a ctor?
subtype = symbGetSubtype( base_ )
+ initree = NULL
+
+ '' Has a ctor?
if( symbGetHasCtor( subtype ) ) then
'' CtorCall
- '' TODO: check whether visibility is checked!
ctorcall = cCtorCall( subtype )
- assert( ctorcall )
-
- '' Will be a CTORCALL except in case of error recovery
- if( astIsCALLCTOR( ctorcall ) ) then
- '' cCtorCall() created a temporary object to
- '' call the constructor on, we delete it though:
- ctorcall = astCALLCTORToCALL( ctorcall )
-
- '' Turn the ctorcall into an initree
- initree = astTypeIniBegin( FB_DATATYPE_STRUCT, subtype, TRUE )
- astTypeIniAddCtorCall( initree, base_, ctorcall )
- astTypeIniEnd( initree, TRUE )
- else
- astDelTree( ctorcall )
- ctorcall = NULL
- initree = NULL
+ if( ctorcall ) then
+ '' Will be a CTORCALL except in case of error recovery
+ if( astIsCALLCTOR( ctorcall ) ) then
+ '' cCtorCall() created a temporary object to
+ '' call the constructor on, we delete it though:
+ ctorcall = astCALLCTORToCALL( ctorcall )
+
+ '' Turn the ctorcall into an initree
+ initree = astTypeIniBegin( FB_DATATYPE_STRUCT, subtype, TRUE )
+ astTypeIniAddCtorCall( initree, base_, ctorcall )
+ astTypeIniEnd( initree, TRUE )
+ else
+ astDelTree( ctorcall )
+ ctorcall = NULL
+ end if
end if
else
'' Initializer
- '' TODO: will this modify the base_ symbol (e.g. setting "inited" flag?)
- '' it shouldn't since this is the field, while base() should be ctor body specific...
initree = cInitializer( base_, FB_INIOPT_ISINI )
end if
View
89 tests/structs/base-init.bas
@@ -182,6 +182,93 @@ namespace podBase
end sub
end namespace
+namespace baseinitIsCtorSpecific1
+ dim shared as integer defctor_count, intctor_count
+ type Parent
+ as integer i
+ declare constructor( )
+ declare constructor( byval as integer )
+ end type
+
+ constructor Parent( )
+ defctor_count += 1
+ this.i = 123
+ end constructor
+
+ constructor Parent( byval i as integer )
+ intctor_count += 1
+ this.i = i
+ end constructor
+
+ type Child extends Parent
+ declare constructor( )
+ declare constructor( byval as integer )
+ end type
+
+ constructor Child( )
+ end constructor
+
+ constructor Child( byval i as integer )
+ base( i )
+ end constructor
+
+ private sub test cdecl( )
+ dim as Child c1
+ CU_ASSERT( c1.i = 123 )
+ CU_ASSERT( defctor_count = 1 )
+ CU_ASSERT( intctor_count = 0 )
+
+ dim as Child c2 = Child( 456 )
+ CU_ASSERT( c2.i = 456 )
+ CU_ASSERT( defctor_count = 1 )
+ CU_ASSERT( intctor_count = 1 )
+ end sub
+end namespace
+
+namespace baseinitIsCtorSpecific2
+ dim shared as integer defctor_count, intctor_count
+ type Parent
+ as integer i
+ declare constructor( )
+ declare constructor( byval as integer )
+ end type
+
+ constructor Parent( )
+ defctor_count += 1
+ this.i = 123
+ end constructor
+
+ constructor Parent( byval i as integer )
+ intctor_count += 1
+ this.i = i
+ end constructor
+
+ type Child extends Parent
+ declare constructor( byval as integer )
+ declare constructor( )
+ end type
+
+ '' Ctor order swapped
+ constructor Child( byval i as integer )
+ base( i )
+ end constructor
+
+ constructor Child( )
+ end constructor
+
+ private sub test cdecl( )
+ dim as Child c1
+ CU_ASSERT( c1.i = 123 )
+ CU_ASSERT( defctor_count = 1 )
+ CU_ASSERT( intctor_count = 0 )
+
+ dim as Child c2 = Child( 456 )
+ CU_ASSERT( c2.i = 456 )
+ CU_ASSERT( defctor_count = 1 )
+ CU_ASSERT( intctor_count = 1 )
+ end sub
+end namespace
+
private sub ctor( ) constructor
fbcu.add_suite( "tests/structs/based-init" )
fbcu.add_test( "Implicit base default ctor call", @implicitBaseDefCtor.test )
@@ -191,6 +278,8 @@ private sub ctor( ) constructor
fbcu.add_test( "BASE() as partial initializer", @explicitBasePartialInit.test )
fbcu.add_test( "BASE() shouldn't overwrite RTTI", @rttiPreserved.test )
fbcu.add_test( "POD base UDTs must be cleared", @podBase.test )
+ fbcu.add_test( "BASE() affects a single ctor only 1", @baseinitIsCtorSpecific1.test )
+ fbcu.add_test( "BASE() affects a single ctor only 2", @baseinitIsCtorSpecific2.test )
end sub
end namespace
Please sign in to comment.
Something went wrong with that request. Please try again.