Menu

#726 Bugs on syntax for declaring and for defining module constructor or module destructor

closed
dkl
None
compiler
2014-05-10
2014-04-18
No

1) No coherence test checked between declaration and definition for module constructor/destructor
First bug:
- For procedures (Sub) with Constructor/Destructor (Module) in their procedure body definitions, Constructor/Destructor (Module) can also be specified in the corresponding declarations, in principle for improved code readability.
- But in that precise case (module constructor/destructor) there is no coherence test between definition and declaration. At declaration level, Constructor/Destructor (Module) is authorized but fully ignored except for verifying that member procedure is well declared as static (at worst, we can declare as a module destructor a procedure defined as a module constructor without compiler error).

Remark:
- For member procedures with Static/Virtual in their declaration, Static/Virtual can also be specified on the corresponding procedure body definitions, for improved code readability, but a coherence test is well executed at the compilation time.

No compiler error (same behavior for a non-member procedure when there is incoherence between declaration and definition)!

Type UDT
  Dim As Integer dummy
  Declare Static Sub init () Constructor  '' incoherence between declaration / definition
End Type

Static Sub UDT.init ()  '' incoherence between declaration / definition
  Print "Init successfull"
End Sub

Print "End"
Sleep

Output:
End


2) Non-static member procedure allowed to be defined as module constructor/destructor
Second bug:
- We can define a non-static member procedure as module Constructor/Destructor (if Constructor/Destructor is not specified also at the declaration level). The program compiles but crashes at run-time.

No compiler error and program crashes!

Type UDT
  Dim As Integer dummy
  Declare Sub init ()  '' non-static member procedure
End Type

Sub UDT.init () Constructor  '' non-static member procedure
  Print "Init successfull"
End Sub

Print "End"
Sleep

Output:
Init successfull
Appuyez sur une touche pour continuer...


3) Private static member procedure allowed to be defined as module constructor/destructor
Rather a final remark:
- A private static member procedure can be defined as module constructor or module destructor.
- This may be subject to discussion, because that possibility can be considered as an initialization similarly to the initialization statement from outside the Type used for a static member variable!

No compiler error and program works.

Type UDT
  Private:
    Dim As Integer dummy
    Declare Static Sub init () Constructor  '' private static member procedure
End Type

Static Sub UDT.init () Constructor  '' Private static member procedure
  Print "Init successfull"
End Sub

Print "End"
Sleep

Output:
Init successfull
End


Referring to forum at http://www.freebasic.net/forum/viewtopic.php?p=196786#p196786

Discussion

  • dkl

    dkl - 2014-04-24
    • status: open --> closed
    • assigned_to: dkl
     

Log in to post a comment.