Skip to content

[clang][Sema] Fix crash when diagnosing candidates with parameter packs #93079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ Bug Fixes to C++ Support
from being explicitly specialized for a given implicit instantiation of the class template.
- Fixed a crash when ``this`` is used in a dependent class scope function template specialization
that instantiates to a static member function.

- Fix crash when inheriting from a cv-qualified type. Fixes #GH35603
- Fix a crash when the using enum declaration uses an anonymous enumeration. Fixes (#GH86790).
- Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a false-positive diagnostic. (#GH84220)
Expand Down Expand Up @@ -796,6 +795,8 @@ Bug Fixes to C++ Support
Fixes (#GH91308).
- Fix a crash caused by a regression in the handling of ``source_location``
in dependent contexts. Fixes (#GH92680).
- Fixed a crash when diagnosing failed conversions involving template parameter
packs. (#GH93076)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
13 changes: 11 additions & 2 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DependenceFlags.h"
Expand Down Expand Up @@ -11301,8 +11302,16 @@ 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;

// FIXME: In presence of parameter packs we can't determine parameter range
// reliably, as we don't have access to instantiation.
bool HasParamPack =
llvm::any_of(Fn->parameters().take_front(I), [](const ParmVarDecl *Parm) {
return Parm->isParameterPack();
});
if (!isObjectArgument && !HasParamPack)
ToParamRange = Fn->getParamDecl(I)->getSourceRange();

if (FromTy == S.Context.OverloadTy) {
assert(FromExpr && "overload set argument came from implicit argument?");
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/overload-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ namespace overloadCheck{
}
}
#endif

namespace GH93076 {
template <typename ...a> int b(a..., int); // expected-note-re 3 {{candidate function template not viable: no known conversion from 'int ()' to 'int' for {{.*}} argument}}
int d() {
(void)b<int, int>(0, 0, d); // expected-error {{no matching function for call to 'b'}}
(void)b<int, int>(0, d, 0); // expected-error {{no matching function for call to 'b'}}
(void)b<int, int>(d, 0, 0); // expected-error {{no matching function for call to 'b'}}
return 0;
}
}
Loading