diff options
author | Jasper Jenkins <jasper.vs.jenkins@gmail.com> | 2019-09-11 23:19:53 -0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-09-12 08:19:53 +0200 |
commit | ca7bf3be8b5641716b9c9e75b0fdca9ca308c0e0 (patch) | |
tree | 78cc1cb3c9656acc7972564eae4cb9877a6ac92f | |
parent | 5783cd67a8eeed8597b0f5d97784c6382aa43396 (diff) | |
download | Nim-ca7bf3be8b5641716b9c9e75b0fdca9ca308c0e0.tar.gz |
no commas for empty importcpp splat params (#12183)
-rw-r--r-- | compiler/ccgcalls.nim | 13 | ||||
-rw-r--r-- | tests/cpp/tempty_generic_obj.nim | 11 |
2 files changed, 17 insertions, 7 deletions
diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 84b59d632..686eb8fde 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -394,11 +394,14 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope = while i < pat.len: case pat[i] of '@': - if j < ri.len: - result.add genOtherArg(p, ri, j, typ) - for k in j+1 ..< ri.len: - result.add(~", ") - result.add genOtherArg(p, ri, k, typ) + var first = true + for k in j ..< ri.len: + let arg = genOtherArg(p, ri, k, typ) + if arg.len > 0: + if not first: + result.add(~", ") + first = false + result.add arg inc i of '#': if i+1 < pat.len and pat[i+1] in {'+', '@'}: diff --git a/tests/cpp/tempty_generic_obj.nim b/tests/cpp/tempty_generic_obj.nim index b61c699f6..d05a82f9a 100644 --- a/tests/cpp/tempty_generic_obj.nim +++ b/tests/cpp/tempty_generic_obj.nim @@ -8,7 +8,7 @@ import typetraits # bug #4625 type - Vector {.importcpp: "std::vector<'0 >", header: "vector".} [T] = object + Vector[T] {.importcpp: "std::vector<'0 >", header: "vector".} = object proc initVector[T](): Vector[T] {.importcpp: "'0(@)", header: "vector", constructor.} @@ -24,7 +24,7 @@ vf.doSomething() # Nim uses doSomething[int] here in C++ # Alternative definition: # https://github.com/nim-lang/Nim/issues/7653 -type VectorAlt* {.importcpp: "std::vector", header: "<vector>", nodecl.} [T] = object +type VectorAlt*[T] {.importcpp: "std::vector", header: "<vector>", nodecl.} = object proc mkVector*[T]: VectorAlt[T] {.importcpp: "std::vector<'*0>()", header: "<vector>", constructor, nodecl.} proc foo(): VectorAlt[cint] = @@ -36,3 +36,10 @@ proc bar(): VectorAlt[cstring] = var x = foo() var y = bar() +proc init[T; Self: Vector[T]](_: typedesc[Self], n: csize): Vector[T] + {.importcpp: "std::vector<'*0>(@)", header: "<vector>", constructor, nodecl.} +proc size[T](x: Vector[T]): csize + {.importcpp: "#.size()", header: "<vector>", nodecl.} + +var z = Vector[int16].init(32) +assert z.size == 32 |