Skip to content

[clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables #70280

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

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ Bug Fixes to C++ Support
whose type is `decltype(auto)`. Fixes (#GH68885).
- Clang now correctly treats the noexcept-specifier of a friend function to be a complete-class context.
- Fix an assertion failure when parsing an invalid members of an anonymous class. (#GH85447)
- Fixed crash when parsing inconsistent arguments in variadic template variables. Fixes (#GH70191)

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 @@ -11370,6 +11370,14 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
I--;
}

bool isVariadic = false;
for (unsigned N = 0; N < Fn->getNumParams(); N++) {
if (Fn->getParamDecl(N)->isParameterPack()) {
isVariadic = true;
break;
}
}

std::string FnDesc;
std::pair<OverloadCandidateKind, OverloadCandidateSelect> FnKindPair =
ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, Cand->getRewriteKind(),
Expand All @@ -11378,8 +11386,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 = !isObjectArgument && !isVariadic
? Fn->getParamDecl(I)->getSourceRange()
: SourceRange();

if (FromTy == S.Context.OverloadTy) {
assert(FromExpr && "overload set argument came from implicit argument?");
Expand Down
9 changes: 9 additions & 0 deletions clang/test/SemaCXX/GH70280.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s

namespace PR70280 {
typedef a; // expected-error {{a type specifier is required for all declarations}}
using b = char*;
template <typename... c> void d(c...) = d<b, a>(0, ""); // expected-error {{no matching function for call to 'd'}}
// expected-error@-1 {{illegal initializer (only variables can be initialized)}}
// expected-note@-2 {{candidate function template not viable: no known conversion from 'const char[1]' to 'a' (aka 'int') for 2nd argument}}
}