diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-04-23 18:39:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 18:39:15 -0700 |
| commit | c6b9a91253bce6d450efc281b3f86617b3eef633 (patch) | |
| tree | 4cfaaf2f298611495601b6287ef2d143420cbcc6 /source | |
| parent | f1de1817ca10e34ec6a844100f10f0de3340c9f2 (diff) | |
Do not diagnose error when a symbols is defined as 'extern' and 'export' (#4010)
Fix the issue (#3999).
For a function is defined as extern and export at the same time, don't
report error, we can use the 'export' function to overload the 'extern'
function.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 7 | ||||
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 14 |
2 files changed, 21 insertions, 0 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 17551912d..cb68dced9 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -6944,6 +6944,13 @@ namespace Slang if (!doFunctionSignaturesMatch(newDeclRef, oldDeclRef)) return SLANG_OK; + // If the declatation is declared by 'extern', and new definition is with 'export', then + // we should let overload resolution to handle it. + if (oldDecl->hasModifier<ExternModifier>() && newDecl->hasModifier<HLSLExportModifier>()) + { + return SLANG_OK; + } + // If we get this far, then we've got two declarations in the same // scope, with the same name and signature, so they appear // to be redeclarations. diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 7a38b08c0..6180ccda8 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1141,6 +1141,15 @@ namespace Slang return 0; } + int getExportRank(DeclRef<Decl> left, DeclRef<Decl> right) + { + if (left.getDecl() && left.getDecl()->hasModifier<ExternModifier>()) + { + return (right.getDecl() && right.getDecl()->hasModifier<HLSLExportModifier>()) ? -1 : 0; + } + return 0; + } + int SemanticsVisitor::CompareOverloadCandidates( OverloadCandidate* left, OverloadCandidate* right) @@ -1214,6 +1223,11 @@ namespace Slang if(specificityDiff) return specificityDiff; + // `export` function is more flavored than `extern` function. But other modifiers are not considered. + auto externExportDiff = getExportRank(left->item.declRef, right->item.declRef); + if (externExportDiff) + return externExportDiff; + // If we reach here, we will attempt to use overload rank to break the ties. auto overloadRankDiff = getOverloadRank(right->item.declRef) - getOverloadRank(left->item.declRef); if (overloadRankDiff) |
