Fix temporary object structured initialization

This commit is contained in:
drmortalwombat 2024-09-21 23:02:59 +02:00
parent d7bfd0a668
commit bcd118a8b3
2 changed files with 28 additions and 16 deletions

View File

@ -2696,6 +2696,10 @@ bool Declaration::CanAssign(const Declaration* fromType) const
return this->CanAssign(fromType->mBase); return this->CanAssign(fromType->mBase);
return false; return false;
} }
else if (mType == DT_TYPE_ARRAY && fromType->mType == DT_TYPE_ARRAY)
{
return mSize == fromType->mSize && mStride == fromType->mStride && mBase->CanAssign(fromType->mBase);
}
else if (mType == DT_TYPE_POINTER) else if (mType == DT_TYPE_POINTER)
{ {
if (fromType->mType == DT_TYPE_POINTER || fromType->mType == DT_TYPE_ARRAY) if (fromType->mType == DT_TYPE_POINTER || fromType->mType == DT_TYPE_ARRAY)

View File

@ -5814,19 +5814,20 @@ Expression* Parser::ParseCastExpression(Expression* exp)
if (mScanner->mToken == TK_OPEN_BRACE) if (mScanner->mToken == TK_OPEN_BRACE)
{ {
Declaration* cdec = new Declaration(mScanner->mLocation, DT_VARIABLE); Declaration* cdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
cdec->mBase = exp->mDecType->ToConstType(); cdec->mFlags |= DTF_CONST | DTF_STATIC | DTF_GLOBAL;
cdec->mFlags |= DTF_CONST | DTF_STATIC | DTF_GLOBAL | DTF_DEFINED; cdec->mBase = exp->mDecType;
Expression* cexp = new Expression(mScanner->mLocation, EX_VARIABLE); Expression* cexp = new Expression(mScanner->mLocation, EX_VARIABLE);
cexp->mDecValue = cdec; cexp->mDecValue = cdec;
cexp->mDecType = cdec->mBase;
cdec->mValue = ParseInitExpression(cdec->mBase); cdec->mValue = ParseInitExpression(cdec->mBase);
cdec->mSection = mDataSection; cdec->mSection = mDataSection;
cdec->mSize = cdec->mBase->mSize; cdec->mSize = cdec->mBase->mSize;
if (mFunctionType)
{
Declaration* vdec = new Declaration(mScanner->mLocation, DT_VARIABLE); Declaration* vdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
vdec->mBase = exp->mDecType; vdec->mBase = cdec->mBase;
vdec->mVarIndex = mLocalIndex++; vdec->mVarIndex = mLocalIndex++;
vdec->mFlags |= DTF_DEFINED; vdec->mFlags |= DTF_DEFINED;
vdec->mSize = vdec->mBase->mSize; vdec->mSize = vdec->mBase->mSize;
@ -5838,10 +5839,17 @@ Expression* Parser::ParseCastExpression(Expression* exp)
Expression* iexp = new Expression(mScanner->mLocation, EX_INITIALIZATION); Expression* iexp = new Expression(mScanner->mLocation, EX_INITIALIZATION);
iexp->mLeft = nexp; iexp->mLeft = nexp;
iexp->mRight = cexp; iexp->mRight = cexp;
iexp->mDecType = exp->mDecType; iexp->mDecType = cdec->mBase;
cdec->mBase = cdec->mBase->ToConstType();
exp = iexp; exp = iexp;
} }
else
exp = cexp;
cexp->mDecType = cdec->mBase;
}
else else
{ {
Expression* nexp = new Expression(mScanner->mLocation, EX_TYPECAST); Expression* nexp = new Expression(mScanner->mLocation, EX_TYPECAST);