Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ codegen regression: memset called on a result variable of importcpp type (v2) #6762

Closed
philip-wernersbach opened this issue Nov 16, 2017 · 2 comments

Comments

@philip-wernersbach
Copy link
Contributor

Version 2 of #5140.

Consider the following:

{.emit:"""
#import <cassert>

class C {
  public:
    int d;

    C(): d(1) { }

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

      d = other.d;
      return *this;
    }
};
""".}

type C* {.final, importc: "C".} = object

proc newC*(): C {.importcpp: "C".}

proc mkC*(): C =
    result = newC()

discard mkC()

The assertion fails because Nim generates a memset for mkC's result:

N_NIMCALL(C, mkc_x4uLyT9aRomf9cN9bUnV4BPJg)(void) {
	C result0;
	nimfr("mkC", "test.nim")
	memset((void*)(&result0), 0, sizeof(result0));
	nimln(24, "test.nim");
	result0 = C();
	popFrame();
	return result0;
}
@Araq
Copy link
Member

Araq commented Nov 17, 2017

But you need to use importcpp to import the type and then the problem disappears.

@Araq Araq closed this as completed Nov 17, 2017
@philip-wernersbach
Copy link
Contributor Author

I see, can't believe I missed this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants