From 4164ec4f8b6d9968e69381edd35d9cf6fe79dee1 Mon Sep 17 00:00:00 2001 From: cooldome Date: Fri, 2 Mar 2018 11:14:41 +0000 Subject: [PATCH] Fixes #6837 (#7271) --- compiler/ccgstmts.nim | 5 ++++- tests/cpp/temitlist.nim | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index a69495a4b7..6b8ba2b025 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -243,7 +243,10 @@ proc genSingleVar(p: BProc, a: PNode) = if params != nil: params.add(~", ") assert(sonsLen(typ) == sonsLen(typ.n)) add(params, genOtherArg(p, value, i, typ)) - lineF(p, cpsStmts, "$#($#);$n", [decl, params]) + if params == nil: + lineF(p, cpsStmts, "$#;$n", [decl]) + else: + lineF(p, cpsStmts, "$#($#);$n", [decl, params]) else: initLocExprSingleUse(p, value, tmp) lineF(p, cpsStmts, "$# = $#;$n", [decl, tmp.rdLoc]) diff --git a/tests/cpp/temitlist.nim b/tests/cpp/temitlist.nim index a7a8ebde47..e88bf45bd4 100644 --- a/tests/cpp/temitlist.nim +++ b/tests/cpp/temitlist.nim @@ -1,6 +1,7 @@ discard """ targets: "cpp" - output: '''6.0''' + output: '''6.0 +0''' """ # bug #4730 @@ -20,3 +21,16 @@ proc main = echo v[0] main() + +#------------ + +#bug #6837 +type StdString {.importCpp: "std::string", header: "", byref.} = object +proc initString(): StdString {.constructor, importCpp: "std::string(@)", header: "".} +proc size(this: var StdString): csize {.importCpp: "size", header: "".} + +proc f(): csize = + var myString: StdString = initString() + return myString.size() + +echo f()