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
Dynamically creating object instances causes segmentation fault #154
Comments
It is a known flaw of nidhugg's frontend (#104, #105) that if you want to use any part of the C++ standard library that is not header-only, you need to compile the standard library to IR yourself and link it to your program under test. Since the c++ standard library does not define As a workaround, you can define your own new and delete in your program under test: void* operator new(std::size_t sz)
{
if (sz == 0)
++sz; // avoid std::malloc(0) which may return nullptr on success
if (void *ptr = std::malloc(sz))
return ptr;
throw std::bad_alloc{};
}
void operator delete(void* ptr) noexcept
{
std::free(ptr);
} I'll think about a medium-term solution so that people can at least call new without workarounds. |
Thanks, that workaround does the job. P.S. Is it |
I suppose either should work. I got the code from cppreference |
Basically, I was trying to use run Nidhugg on a class implementation and fell on this error. A minimal example to reproduce the segmentation fault I encountered is the following:
The error that Nidhuggs displays is the following :
Note that if I remove the
x
variable only the warning remains and Nidhugg does not produce the segmentation fault. Also, if I instantiate my class object withoutnew
then Nidhugg does not produce neither a warning nor a segmentation fault (however it is crucial for my application to dynamically create the object).The text was updated successfully, but these errors were encountered: