mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
marking a field with noInit allows to skip constructor initialiser (#22802)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
30
tests/cpp/tnoinitfield.nim
Normal file
30
tests/cpp/tnoinitfield.nim
Normal file
@@ -0,0 +1,30 @@
|
||||
discard """
|
||||
targets: "cpp"
|
||||
cmd: "nim cpp $file"
|
||||
output: '''
|
||||
'''
|
||||
"""
|
||||
{.emit: """/*TYPESECTION*/
|
||||
struct Foo {
|
||||
Foo(int a){};
|
||||
};
|
||||
struct Boo {
|
||||
Boo(int a){};
|
||||
};
|
||||
|
||||
""".}
|
||||
|
||||
type
|
||||
Foo {.importcpp.} = object
|
||||
Boo {.importcpp, noInit.} = object
|
||||
Test {.exportc.} = object
|
||||
foo {.noInit.}: Foo
|
||||
boo: Boo
|
||||
|
||||
proc makeTest(): Test {.constructor: "Test() : foo(10), boo(1)".} =
|
||||
discard
|
||||
|
||||
proc main() =
|
||||
var t = makeTest()
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user