summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-12-22 16:43:37 +0100
committerAraq <rumpf_a@web.de>2016-12-22 16:43:37 +0100
commit0ef6815529a59d4dfd7bd15a87b24dde7d4456b0 (patch)
tree6ca11dba21695a9a10478b9bf7610c358a437247
parent237e2664e0f4f091bc7d1d288291287440f41fbd (diff)
downloadNim-0ef6815529a59d4dfd7bd15a87b24dde7d4456b0.tar.gz
fixes #5140
-rw-r--r--compiler/ccgtypes.nim4
-rw-r--r--tests/cpp/tdont_init_instantiation.nim28
2 files changed, 31 insertions, 1 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 2e403a61d..a173095e8 100644
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -207,7 +207,9 @@ proc isImportedType(t: PType): bool =
   result = t.sym != nil and sfImportc in t.sym.flags
 
 proc isImportedCppType(t: PType): bool =
-  result = t.sym != nil and sfInfixCall in t.sym.flags
+  let x = t.skipTypes(irrelevantForBackend)
+  result = (t.sym != nil and sfInfixCall in t.sym.flags) or
+           (x.sym != nil and sfInfixCall in x.sym.flags)
 
 proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope
 proc needsComplexAssignment(typ: PType): bool =
diff --git a/tests/cpp/tdont_init_instantiation.nim b/tests/cpp/tdont_init_instantiation.nim
new file mode 100644
index 000000000..7d4bf322a
--- /dev/null
+++ b/tests/cpp/tdont_init_instantiation.nim
@@ -0,0 +1,28 @@
+discard """
+  cmd: "nim cpp $file"
+  output: ''''''
+"""
+
+# bug #5140
+{.emit:"""
+#import <cassert>
+
+template <typename X> class C {
+  public:
+    int d;
+
+    C(): d(1) { }
+
+    C<X>& operator=(const C<X> other) {
+      assert(d == 1);
+    }
+};
+""".}
+
+type C{.importcpp, header: "<stdio.h>", nodecl.} [X] = object
+proc mkC[X]: C[X] {.importcpp: "C<'*0>()", constructor, nodecl.}
+
+proc foo(): C[int] =
+  result = mkC[int]()
+
+discard foo()