Skip to content

Commit 7840ea2

Browse files
committed
[clang][Sema] Fix crash when diagnosing candidates with parameter packs
Prevent OOB access. Fixes #93076
1 parent 135ddd8 commit 7840ea2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/Sema/SemaOverload.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
1129811298
Expr *FromExpr = Conv.Bad.FromExpr;
1129911299
QualType FromTy = Conv.Bad.getFromType();
1130011300
QualType ToTy = Conv.Bad.getToType();
11301-
SourceRange ToParamRange =
11302-
!isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : SourceRange();
11301+
SourceRange ToParamRange;
11302+
if (!isObjectArgument && I < Fn->getNumParams())
11303+
ToParamRange = Fn->getParamDecl(I)->getSourceRange();
1130311304

1130411305
if (FromTy == S.Context.OverloadTy) {
1130511306
assert(FromExpr && "overload set argument came from implicit argument?");

clang/test/SemaCXX/overload-template.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ namespace overloadCheck{
5858
}
5959
}
6060
#endif
61+
62+
template <typename ...a> int b(a...); // expected-note {{candidate function template not viable: no known conversion from 'int ()' to 'int' for 2nd argument}}
63+
int d() { return b<int, int>(0, d); } // expected-error {{no matching function for call to 'b'}}

0 commit comments

Comments
 (0)