From 174205bcae62e3c954096a2ff557ad2184ad9817 Mon Sep 17 00:00:00 2001 From: mjendrusch Date: Sun, 17 Apr 2016 17:10:24 +0200 Subject: [PATCH 1/2] Fixes #4093 Added COMMA macro to nimbase.h, changed code generation for c++ template types to insert COMMA im between the arguments, instead of ",". --- compiler/ccgtypes.nim | 2 +- lib/nimbase.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 39f16ff0dc..ab40fff735 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -654,7 +654,7 @@ proc getTypeDescAux(m: BModule, typ: PType, check: var IntSet): Rope = else: result = cppName & "<" for i in 1 .. typ.len-2: - if i > 1: result.add(", ") + if i > 1: result.add(" COMMA ") result.add(getTypeDescAux(m, typ.sons[i], check)) result.add("> ") # always call for sideeffects: diff --git a/lib/nimbase.h b/lib/nimbase.h index 5a4f403b62..f531f3c490 100644 --- a/lib/nimbase.h +++ b/lib/nimbase.h @@ -222,6 +222,8 @@ __clang__ /* ----------------------------------------------------------------------- */ +#define COMMA , + #include #include From 01ca3ba26d28c5f645b0fc30fca1f386970d120d Mon Sep 17 00:00:00 2001 From: mjendrusch Date: Sun, 17 Apr 2016 17:11:02 +0200 Subject: [PATCH 2/2] Added test case Previously offending code --- tests/cpp/ttemplatetype.nim | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/cpp/ttemplatetype.nim diff --git a/tests/cpp/ttemplatetype.nim b/tests/cpp/ttemplatetype.nim new file mode 100644 index 0000000000..7f56a225d9 --- /dev/null +++ b/tests/cpp/ttemplatetype.nim @@ -0,0 +1,9 @@ +type + Map {.importcpp: "std::map", header: "".} [T,U] = object + +proc cInitMap(T: typedesc, U: typedesc): Map[T,U] {.importcpp: "std::map<'*1,'*2>()", nodecl.} + +proc initMap[T, U](): Map[T, U] = + result = cInitMap(T, U) + +var x: Map[cstring, cint] = initMap[cstring, cint]()