summary refs log tree commit diff stats
path: root/tests/cpp/torc.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cpp/torc.nim')
-rw-r--r--tests/cpp/torc.nim34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/cpp/torc.nim b/tests/cpp/torc.nim
index 64c6c0e5f..9f1a41a21 100644
--- a/tests/cpp/torc.nim
+++ b/tests/cpp/torc.nim
@@ -39,3 +39,37 @@ proc asVector*[T](t: T): EnumVector[T] =
 # N_NIMCALL(std::vector<> , asvector_106028_3197418230)(SomeEnum t0)
 
 discard asVector(SomeEnum.A)
+
+
+block: # bug #10219
+  type
+    Vector[T]  {.importcpp: "std::vector", header: "vector".} = object
+
+  proc initVector[T](n: csize_t): Vector[T] 
+      {.importcpp: "std::vector<'*0>(@)", header: "vector".}
+
+  proc unsafeIndex[T](this: var Vector[T], i: csize_t): var T 
+      {.importcpp: "#[#]", header: "vector".}
+
+  proc `[]`[T](this: var Vector[T], i: Natural): var T {.inline, noinit.} =
+    when compileOption("boundChecks"):
+        # this.checkIndex i
+        discard
+    result = this.unsafeIndex(csize_t(i))
+
+  var v1 = initVector[int](10)
+  doAssert v1[0] == 0
+
+block: # bug #12703 bug #19588
+  type
+    cstringConstImpl {.importc:"const char*".} = cstring
+    constChar = distinct cstringConstImpl
+
+  {.emit: """
+  const char* foo() {
+    return "hello";
+  }
+  """.}
+  proc foo(): constChar {.importcpp.} # change to importcpp for C++ backend
+  doAssert $(foo().cstring) == "hello"
+