Hey, wanted to report a bug that causes the compiler to crash when building a module, here's a minimal C++ example:
#include <angelscript.h>
static void Constructor(asIScriptGeneric* gen)
{
}
static void Destructor(void* mem)
{
}
int main()
{
auto engine = asCreateScriptEngine();
engine->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, true);
engine->RegisterObjectType("ptr<class T>", sizeof(void*), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_TEMPLATE | asOBJ_APP_CLASS | asOBJ_APP_CLASS_CD);
engine->RegisterObjectBehaviour("ptr<T>", asBEHAVE_CONSTRUCT, "void f(int&in, ?&inout)", asFUNCTION(Constructor), asCALL_GENERIC);
engine->RegisterObjectBehaviour("ptr<T>", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJFIRST);
auto mod = engine->GetModule("Module", asGM_ALWAYS_CREATE);
mod->AddScriptSection("Section", "void Main() { ptr<int>(null); }");
mod->Build();
return 0;
}
It seems that passing null
into an &inout parameter crashes, when it should throw a compile error that null is not a valid reference instead, This seems to happen only in a specific case where the class that contains the method is a template type. I can reproduce this on the latest rev 2807.
I'm including a patch for a possible fix: https://gist.github.com/donadigo/3d7e39ee05d97f46b2f1bfb10355a9c4. I'm not sure if this is the way to go but it does fix the issue while passing all tests here.