@@ -3783,22 +3783,26 @@ void Deallocate(TCppScope_t scope, TCppObject_t address, TCppIndex_t count) {
3783
3783
// FIXME: Add optional arguments to the operator new.
3784
3784
TCppObject_t Construct (compat::Interpreter& interp, TCppScope_t scope,
3785
3785
void * arena /* =nullptr*/ , TCppIndex_t count /* =1UL*/ ) {
3786
- auto * Class = (Decl*)scope;
3787
- // FIXME: Diagnose.
3788
- if (!HasDefaultConstructor (Class))
3789
- return nullptr ;
3790
3786
3791
- auto * const Ctor = GetDefaultConstructor (interp, Class);
3792
- if (JitCall JC = MakeFunctionCallable (&interp, Ctor)) {
3793
- if (arena) {
3794
- JC.InvokeConstructor (&arena, count, {},
3795
- (void *)~0 ); // Tell Invoke to use placement new.
3796
- return arena;
3797
- }
3787
+ TCppFunction_t ctor;
3788
+ if (Cpp::IsConstructor (scope))
3789
+ ctor = scope;
3790
+ else if (Cpp::IsClass (scope)) {
3791
+ if (!HasDefaultConstructor (scope))
3792
+ return nullptr ;
3793
+ ctor = Cpp::GetDefaultConstructor (scope);
3794
+ } else
3795
+ return nullptr ;
3798
3796
3799
- void * obj = nullptr ;
3800
- JC.InvokeConstructor (&obj, count, {}, nullptr );
3801
- return obj;
3797
+ if (JitCall JC = MakeFunctionCallable (&interp, ctor)) {
3798
+ if (JC.getKind () != Cpp::JitCall::kConstructorCall )
3799
+ return nullptr ;
3800
+ // invoke the constructor (placement/heap) in one shot
3801
+ // flag is non-null for placement new, null for normal new
3802
+ void * flag = arena ? reinterpret_cast <void *>(1 ) : nullptr ;
3803
+ void * result = arena;
3804
+ JC.InvokeConstructor (&result, count, {}, flag);
3805
+ return result;
3802
3806
}
3803
3807
return nullptr ;
3804
3808
}
0 commit comments