summary refs log tree commit diff stats
path: root/tests/cpp
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2019-01-17 07:55:29 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-01-17 07:55:29 +0100
commit15584879b91e14565156ca140eef1dc100cf34c4 (patch)
tree72a6456a09c453542f3f6b4c02e9ece9d9635dda /tests/cpp
parent52a54f5f042f2849b50c244332e3169fdc03e194 (diff)
downloadNim-15584879b91e14565156ca140eef1dc100cf34c4.tar.gz
Properly wrap discarded statements (#10322)
Failing to do so lead the codegen to emit invalid code sometimes,
especially when C++ references were involved.

Fixes #10241
Diffstat (limited to 'tests/cpp')
-rw-r--r--tests/cpp/t10241.nim19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/cpp/t10241.nim b/tests/cpp/t10241.nim
new file mode 100644
index 000000000..21d6a0f4e
--- /dev/null
+++ b/tests/cpp/t10241.nim
@@ -0,0 +1,19 @@
+discard """
+  targets: "cpp"
+  action: "compile"
+"""
+
+type
+  String* {.importcpp: "std::string", header: "string".} = object
+
+proc initString*(): String
+    {.importcpp: "std::string()", header: "string".}
+
+proc append*(this: var String, str: String): var String
+    {.importcpp: "append", header: "string", discardable.}
+
+var
+  s1 = initString()
+  s2 = initString()
+
+s1.append s2