C++ codegen regression: memset called on a result variable of `importcpp` type #5140

nigredo-tori opened this Issue Dec 22, 2016 · 0 comments


None yet

1 participant

nigredo-tori commented Dec 22, 2016 edited

Reduced example:

#import <cassert>

template <typename X> class C {
    int d;

    C(): d(1) { }

    C<X>& operator=(const C<X> other) {
      assert(d == 1);

type C{.importcpp, header: "<stdio.h>", nodecl.} [X] = object
proc mkC[X]: C[X] {.importcpp: "C<'*0>()", constructor, nodecl.}

proc foo(): C[int] =
  result = mkC[int]()

discard foo()

The assertion fails, because the generated code for foo looks like this:

C<NI>  result0;
nimfr("foo", "test_default_constructor.nim")
memset((void*)(&result0), 0, sizeof(result0));
nimln(20, "test_default_constructor.nim");
result0 = C<NI>();
return result0;

This memset breaks use cases relying on default constructor (in my case this was QList).

Tested on: 80f9dcc
Bisect points to: 860cbd3

@Araq Araq added a commit that closed this issue Dec 22, 2016
@Araq Araq fixes #5140 0ef6815
@Araq Araq closed this in 0ef6815 Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment