Fix const struct parameter overload matching

This commit is contained in:
drmortalwombat 2025-05-08 13:50:51 +02:00
parent b4a357e44f
commit 34fda8c9b5
3 changed files with 29 additions and 0 deletions

View File

@ -31,6 +31,17 @@ DeclarationScope::~DeclarationScope(void)
delete[] mHash;
}
DeclarationScope* DeclarationScope::Clone(void) const
{
DeclarationScope* scope = new DeclarationScope(mParent, mLevel, mName);
for (int i = 0; i < mHashSize; i++)
{
if (mHash[i].mIdent)
scope->Insert(mHash[i].mIdent, mHash[i].mDec);
}
return scope;
}
const Ident* DeclarationScope::Mangle(const Ident* ident) const
{
if (mName && ident)

View File

@ -166,6 +166,8 @@ public:
ScopeLevel mLevel;
const Ident * mName;
DeclarationScope* Clone(void) const;
DeclarationScope* mParent;
protected:
struct Entry

View File

@ -7483,6 +7483,21 @@ int Parser::OverloadDistance(Declaration* fdec, Expression* pexp)
{
dist += 32;
}
else if (ptype->mType == DT_TYPE_STRUCT && etype->mType == DT_TYPE_STRUCT)
{
int ncast = 0;
Declaration* ext = ex->mDecType;
while (ext && !ext->IsConstSame(ptype))
{
ncast++;
ext = ext->mBase;
}
if (ext)
dist += 32 * ncast;
else
return NOOVERLOAD;
}
else
return NOOVERLOAD;
@ -11149,6 +11164,7 @@ Declaration* Parser::ParseTemplateExpansion(Declaration* tmpld, Declaration* exp
p->mScanner->Replay(tmpld->mBase->mTokens);
tdec = tmpld->mBase->Clone();
tdec->mScope = tdec->mScope->Clone();
tdec->mScope->mName = expd->mScope->mName;
tdec->mScope->mParent = expd->mScope;