C++ Adds support for default arg using object construction syntax. Fixes a compiler crash (#22768)

`Foo()` below makes the compiler crash. 
```nim

proc makeBoo(a:cint = 10, b:cstring = "hello", foo: Foo = Foo()): Boo {.importcpp, constructor.}

```
This commit is contained in:
Juan M Gómez
2023-09-28 17:08:42 +01:00
committed by GitHub
parent 285cbcb6aa
commit 4fffa0960f
2 changed files with 35 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
discard """
targets: "cpp"
cmd: "nim cpp $file"
"""
{.emit:"""/*TYPESECTION*/
@@ -30,4 +30,31 @@ proc main =
discard returnCppStruct() #generates result = { 10 }
discard initChildStruct() #generates ChildStruct temp ({}) bypassed with makeChildStruct
(proc (s:CppStruct) = discard)(CppStruct()) #CppStruct temp ({10})
main()
main()
#Should handle ObjectCalls
{.emit:"""/*TYPESECTION*/
struct Foo {
};
struct Boo {
Boo(int x, char* y, Foo f): x(x), y(y), foo(f){}
int x;
char* y;
Foo foo;
};
""".}
type
Foo {.importcpp, inheritable, bycopy.} = object
Boo {.importcpp, inheritable.} = object
x: int32
y: cstring
foo: Foo
proc makeBoo(a:cint = 10, b:cstring = "hello", foo: Foo = Foo()): Boo {.importcpp, constructor.}
proc main2() =
let cppStruct = makeBoo()
(proc (s:Boo) = discard)(Boo())
main2()