You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
requiresInit should forbid (during sempass) var a: A or var a = default(A) if A is a C++ struct/class with no default constructor; but currently it only gives a cgen error; that's the lower priority bug since the code is invalid anyway
the more annoying bug is that var a = A(args) doesn't work at module scope due to current cgen implementation
Example
{.emit:"""#include <stdio.h>struct A{ A(int a){ printf("ctor\n"); } ~A(){ printf("dtor\n"); }};""".}
type A {.importcpp: "A", requiresInit.} =objectprocinitA(a: cint): A {.importcpp: "A(@)", constructor.}
procfun() =var a1 =initA(12) # ok: this works# var a2: A # BUG: this should give semphase error but give cgen error# var a3 = default(A) # BUG: dittofun()
var a4 =initA(12) # BUG: this doesn't work but should
Current Output
@mt10772.nim.cpp:63:17: error: no matching constructor for initialization of 'A'
Expected Output
works
Possible Solution
cgen should instead use pointers for all global importcpp variables (regardless of whether they have default ctor or not):
These statements no longer cause an error at the module scope:
let tft = initIli9321(9, 10)
Introduces a C++ subclass with a default constructor.
Workaround for nim-lang/Nim#14389
requiresInit
should forbid (during sempass)var a: A
orvar a = default(A)
ifA
is a C++ struct/class with no default constructor; but currently it only gives a cgen error; that's the lower priority bug since the code is invalid anywayvar a = A(args)
doesn't work at module scope due to current cgen implementationExample
Current Output
Expected Output
Possible Solution
cgen should instead use pointers for all global importcpp variables (regardless of whether they have default ctor or not):
instead of generating:
the compiler should generate:
Additional Information
The text was updated successfully, but these errors were encountered: