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()