summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/ccgtypes.nim2
-rw-r--r--tests/cpp/tempty_generic_obj.nim22
2 files changed, 23 insertions, 1 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 0c06354d8..dee98aab8 100644
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -546,7 +546,7 @@ proc getTypeDescAux(m: BModule, typ: PType, check: var IntSet): Rope =
   of tyRef, tyPtr, tyVar:
     var star = if t.kind == tyVar and tfVarIsPtr notin typ.flags and
                     compileToCpp(m): "&" else: "*"
-    var et = t.lastSon
+    var et = typ.skipTypes(abstractInst).lastSon
     var etB = et.skipTypes(abstractInst)
     if etB.kind in {tyArrayConstr, tyArray, tyOpenArray, tyVarargs}:
       # this is correct! sets have no proper base type, so we treat
diff --git a/tests/cpp/tempty_generic_obj.nim b/tests/cpp/tempty_generic_obj.nim
new file mode 100644
index 000000000..e2957a5cd
--- /dev/null
+++ b/tests/cpp/tempty_generic_obj.nim
@@ -0,0 +1,22 @@
+discard """
+  cmd: "nim cpp $file"
+  output: '''int
+float'''
+"""
+
+import typetraits
+
+# bug #4625
+type
+  Vector {.importcpp: "std::vector<'0 >", header: "vector".} [T] = object
+
+proc initVector[T](): Vector[T] {.importcpp: "'0(@)", header: "vector", constructor.}
+
+proc doSomething[T](v: var Vector[T]) =
+  echo T.name
+
+var v = initVector[int]()
+v.doSomething()
+
+var vf = initVector[float]()
+vf.doSomething() # Nim uses doSomething[int] here in C++