[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 23 11:37:16 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();
----------------
mizvekov wrote:
Sure, fixing the crash is important, but in that case I would leave a FIXME and keep the bug open, with updated information. It's your call.
Though I don't think solving this is complicated: Just a linear scan on the parameter list:
* A parameter which is a pack consumes `cast<PackExpansionType>(Fn->getParamDecl(I)->getType())->getNumExpansions()` arguments, which can possibly be zero arguments. It should not be possible to find an unexpanded pack in this diagnostic.
* A parameter which is not a pack consumes one argument.
https://github.com/llvm/llvm-project/pull/93079
More information about the cfe-commits
mailing list