From 0ef6815529a59d4dfd7bd15a87b24dde7d4456b0 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 22 Dec 2016 16:43:37 +0100 Subject: [PATCH] fixes #5140 --- compiler/ccgtypes.nim | 4 +++- tests/cpp/tdont_init_instantiation.nim | 28 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/cpp/tdont_init_instantiation.nim diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 2e403a61d5d8..a173095e8c49 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 000000000000..7d4bf322a6ba --- /dev/null +++ b/tests/cpp/tdont_init_instantiation.nim @@ -0,0 +1,28 @@ +discard """ + cmd: "nim cpp $file" + output: '''''' +""" + +# bug #5140 +{.emit:""" +#import + +template class C { + public: + int d; + + C(): d(1) { } + + C& operator=(const C other) { + assert(d == 1); + } +}; +""".} + +type C{.importcpp, header: "", nodecl.} [X] = object +proc mkC[X]: C[X] {.importcpp: "C<'*0>()", constructor, nodecl.} + +proc foo(): C[int] = + result = mkC[int]() + +discard foo()