[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu May 23 07:01:44 PDT 2024
================
@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
Expr *FromExpr = Conv.Bad.FromExpr;
QualType FromTy = Conv.Bad.getFromType();
QualType ToTy = Conv.Bad.getToType();
- SourceRange ToParamRange =
- !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : SourceRange();
+ SourceRange ToParamRange;
+ if (!isObjectArgument && I < Fn->getNumParams())
+ ToParamRange = Fn->getParamDecl(I)->getSourceRange();
----------------
kadircet wrote:
that's a fair point, I was mostly operating with the assumption of "parameter pack is always the last parameter", but that isn't necessarily true.
as you pointed out this patch prevents the OOB access, and won't necessarily do the "right" thing in terms of pointing at the failed conversion. but this patch is still an improvement to today's case of just crashing even before printing the candidate.
I think adjusting the parameter range to be accurate in presence of parameter packs is more of a feature request at this point. since (AFAICT) it requires propagating extra information in the bad conversion about the parameter location. so I'd rather move forward with this patch, while filing a feature request for the "ideal" state. WDYT?
https://github.com/llvm/llvm-project/pull/93079
More information about the cfe-commits
mailing list