I just integrated the latest angelscript version in our branch (2.21.2). We we're previously using version 2.21.0. Since then, I have some unit tests which are no longer running correctly on Win32 ( haven't tested any other platforms yet ). They seem to be related to the Return Value on Stack optimisation. Here's my test code :
//------------------------------------------------------------------------
struct Castee
{
Castee()
{}
Castee(int v)
: m_v(v)
{}
Castee& operator=(const Castee& rhs)
{
m_v = rhs.m_v;
return *this;
}
int GetValue() const
{
return m_v;
}
int m_v;
};
//------------------------------------------------------------------------
struct Caster
{
Caster()
{}
Caster(int v)
: m_v(v)
{}
operator Castee() const
{
return Castee(m_v);
}
int m_v;
};
//------------------------------------------------------------------------
TEST_FIXTURE( RegistrationFixture, Test_Can_Register_An_Implicit_Value_Cast )
{
using namespace Onyx::AngelScript;
Global(m_registry)
[
ValueClass< Castee >("Castee")
[
Method("int GetValue()", &Castee::GetValue)
],
ValueClass< Caster >("Caster")
[
Constructor< Caster, int >("void f(int i)"),
ImplicitCast("Castee", &Caster::operator Castee)
]
];
m_registry.Finalize();
SetTestCode("\
int Run()\
{\
return GetValueFromCastee(Caster(5));\
}\
\
int GetValueFromCastee(Castee castee)\
{\
return castee.GetValue();\
}\
");
m_context->Prepare(GetFunctionId("int Run()"));
m_context->Execute();
CHECK_EQUAL(5, m_context->GetReturnDWord());
CHECK_ANGELSCRIPT_HAS_NOT_LOGGED_ERRORS_OR_WARNINGS(*this);
}
//------------------------------------------------------------------------
TEST_FIXTURE( RegistrationFixture, Test_Can_Register_An_Explicit_Value_Cast )
{
Global(m_registry)
[
ValueClass< Castee >("Castee")
[
Method("int GetValue()", &Castee::GetValue),
Method("Castee& opAssign(const Castee& in)", &Castee::operator=)
],
ValueClass< Caster >("Caster")
[
Constructor< Caster, int >("void f(int i)"),
ExplicitCast("Castee", &Caster::operator Castee)
]
];
m_registry.Finalize();
SetTestCode("\
int Run()\
{\
Caster caster(5);\
return GetValueFromCastee(Castee(caster));\
}\
\
int GetValueFromCastee(Castee castee)\
{\
return castee.GetValue();\
}\
");
m_context->Prepare(GetFunctionId("int Run()"));
m_context->Execute();
CHECK_EQUAL(5, m_context->GetReturnDWord());
CHECK_ANGELSCRIPT_HAS_NOT_LOGGED_ERRORS_OR_WARNINGS(*this);
}
The code of the ImplicitCast and ExplicitCast function basically registers the asBEHAVE_IMPLICIT_VALUE_CAST or asBEHAVE_VALUE_CAST functions.
Any idea ? I've traced within as_compiler.cpp, and I suspect that the return on the stack directly is to blame here. I get the following error : "[1, 65] There is no copy operator for this type available". If I define AS_OLD, I no longer get any errors.
Any help would be appreciated.