From ad86a362122524ce6ea8688f49b7b61c4ec8076a Mon Sep 17 00:00:00 2001 From: Clonkk Date: Mon, 28 Jun 2021 11:06:44 +0200 Subject: [PATCH 1/2] add reproducible tests for 15 until I can investigate --- tests/destroy_bug_15.nim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/destroy_bug_15.nim diff --git a/tests/destroy_bug_15.nim b/tests/destroy_bug_15.nim new file mode 100644 index 0000000..99735ca --- /dev/null +++ b/tests/destroy_bug_15.nim @@ -0,0 +1,28 @@ +import cppstl/std_vector + +type Foo = object + x: int + +proc `=destroy`*(a: var Foo) {.inline.} = + echo ("in destroy", a.x) + +proc main = + var v = initCppVector[Foo]() + + v.add Foo(x: 10) + v.add Foo(x: 11) + v.add Foo(x: 12) + + echo "ok0" + echo v + + echo "ok1" + echo v + + echo "ok2" + + # Clear should call object destructor + v.clear() + echo "ok3" + +main() From c3ba630dd33a3f90c3d51a8fb59d1674185ff680 Mon Sep 17 00:00:00 2001 From: Clonkk Date: Mon, 28 Jun 2021 11:06:51 +0200 Subject: [PATCH 2/2] apply nimpretty to source --- cppstl/std_complex.nim | 4 ++-- cppstl/std_string.nim | 4 ++-- cppstl/std_vector.nim | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cppstl/std_complex.nim b/cppstl/std_complex.nim index f947099..ca45d93 100644 --- a/cppstl/std_complex.nim +++ b/cppstl/std_complex.nim @@ -31,11 +31,11 @@ func conj*[T: SomeFloat](self: CppComplex[T]): CppComplex[T] {.importcpp: "std:: {.pop.} import complex -proc toComplex*[T](c: CppComplex[T]) : Complex[T] = +proc toComplex*[T](c: CppComplex[T]): Complex[T] = result.re = c.real() result.im = c.imag() -proc toCppComplex*[T](c: Complex[T]) : CppComplex[T] = +proc toCppComplex*[T](c: Complex[T]): CppComplex[T] = result = initCppComplex(c.re, c.im) proc `$`*[T](c: CppComplex[T]): string = diff --git a/cppstl/std_string.nim b/cppstl/std_string.nim index 0bf332c..b4b7c81 100644 --- a/cppstl/std_string.nim +++ b/cppstl/std_string.nim @@ -287,7 +287,7 @@ proc last*(v: CppString): cchar {.inline.} = v.back() # Nim Iterators -iterator items*(v: CppString): cchar= +iterator items*(v: CppString): cchar = ## Iterate over all the elements in CppString `v`. for idx in 0.csize_t ..< v.len(): yield v[idx] @@ -297,7 +297,7 @@ iterator pairs*(v: CppString): (csize_t, cchar) = for idx in 0.csize_t ..< v.len(): yield (idx, v[idx]) -iterator mitems*(v: var CppString): var cchar= +iterator mitems*(v: var CppString): var cchar = ## Iterate over all the elements in CppString `v`. for idx in 0.csize_t ..< v.len(): yield v[idx] diff --git a/cppstl/std_vector.nim b/cppstl/std_vector.nim index a444015..0bb7824 100644 --- a/cppstl/std_vector.nim +++ b/cppstl/std_vector.nim @@ -483,7 +483,7 @@ proc last*[T](v: CppVector[T]): T {.inline.} = # Nim Iterators -iterator items*[T](v: CppVector[T]): T= +iterator items*[T](v: CppVector[T]): T = ## Iterate over all the elements in CppVector `v`. runnableExamples: var