I don't understand this restriction for using 'Any' with 'New' for an UDT with constructor (explicit or implicit), while a static instance of a such UDT (with constructor explicit or implicit) can be constructed with 'Dim ... = Any' ('Any' as fake initializer) and this last syntax works well!
Example with 'New (placement)':
Type UDT
Declare Constructor ()
Dim As Integer I = 1234
End Type
Constructor UDT ()
This.I = 5678
End Constructor
Dim As UDT u = Any '' OK
Print u.I
'Dim As UDT Ptr pu = New(@u) UDT (Any) '' error 7: Expected ')', found 'Any'
Dim As UDT Ptr pu = @u '' workaround
Print pu->I
Sleep
More generally:
If we want to keep the interest of these 4 different syntaxes:
compared respectively to the 4 followings:
it would require that the first 4 syntaxes work also for an UDT with constructor.
Otherwise, for easier use, perhaps completely ban 'Any' (with 'New') for all UDT.
Referring to forum, from the post:
http://www.freebasic.net/forum/viewtopic.php?p=201863#p201863
See also this other bug report:
https://sourceforge.net/p/fbc/bugs/1013/
1013 Non-optimization bug for 'New[]' / 'Delete[]' when datatype has no 'Constructor' (and without '{Any}' initializer)
Both could be addressed simultaneously.
I started the topic "Validity/Behavior of 'ANY' initializer versus datatypes with default constructor":
https://www.freebasic.net/forum/viewtopic.php?t=33278
to discuss and decide on the usage and behavior of 'Any' versus objects with constructors.
Currently, the behavior of 'Any' varies greatly, depending on the data type and declaration type.
Therefore, processing of this bug report is suspended for the time being.
Last edit: fxm (freebasic.net) 2025-08-09