summary refs log tree commit diff stats
path: root/tests/cpp
diff options
context:
space:
mode:
authorJuan M Gómez <info@jmgomez.me>2024-08-18 12:21:17 +0100
committerGitHub <noreply@github.com>2024-08-18 13:21:17 +0200
commit2e4d344b43b040a4dce2c478ca13e49979e491fc (patch)
treec6955db79990e79696e0b1d05311872d6d280489 /tests/cpp
parentf7c11a8978a1fc7182ef18c4bdc80e920ce6ad88 (diff)
downloadNim-2e4d344b43b040a4dce2c478ca13e49979e491fc.tar.gz
Fixes #23962 `resetLoc`doenst produce any cgen code in `importcpp` types (#23964)
Diffstat (limited to 'tests/cpp')
-rw-r--r--tests/cpp/23962.h17
-rw-r--r--tests/cpp/t23962.nim32
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/cpp/23962.h b/tests/cpp/23962.h
new file mode 100644
index 000000000..2d8147bfb
--- /dev/null
+++ b/tests/cpp/23962.h
@@ -0,0 +1,17 @@
+#include <iostream>
+
+struct Foo {
+
+  Foo(int inX): x(inX) {
+    std::cout << "Ctor Foo(" << x << ")\n";
+  }
+  ~Foo() {
+    std::cout << "Destory Foo(" << x << ")\n";
+  }
+
+  void print() {
+    std::cout << "Foo.x = " << x << '\n';
+  }
+
+  int x;
+};
\ No newline at end of file
diff --git a/tests/cpp/t23962.nim b/tests/cpp/t23962.nim
new file mode 100644
index 000000000..c79d888df
--- /dev/null
+++ b/tests/cpp/t23962.nim
@@ -0,0 +1,32 @@
+discard """
+  cmd: "nim cpp $file"
+  output: '''
+Ctor Foo(-1)
+Destory Foo(-1)
+Ctor Foo(-1)
+Destory Foo(-1)
+Ctor Foo(-1)
+Destory Foo(-1)
+Foo.x = 1
+Foo.x = 2
+Foo.x = -1
+'''
+"""
+
+type
+  Foo {.importcpp, header: "23962.h".} = object
+    x: cint
+
+proc print(f: Foo) {.importcpp.}
+
+#also tests the right constructor is used
+proc makeFoo(x: int32 = -1): Foo {.importcpp:"Foo(#)", constructor.} 
+
+proc test =
+  var xs = newSeq[Foo](3)
+  xs[0].x = 1
+  xs[1].x = 2
+  for x in xs:
+    x.print
+
+test()
\ No newline at end of file