[clang] [clang][Sema] Fix crash when diagnosing candidates with parameter packs (PR #93079)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Wed May 22 11:32:19 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:
It seems like the problem here may be that `I` is an index into an argument-as-written list, which doesn't take into account that mapping into the parameter list needs to consider packs.
I think this could do the wrong thing if there are other parameters after the pack.
How does your patch handle the following example?
```C++
template <typename ...a> int b(a..., int);
int d() { return b<int, int>(0, 0, d); }
```
https://github.com/llvm/llvm-project/pull/93079
More information about the cfe-commits
mailing list