Skip to content
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

Fix crash when a lambda contains a constrained parameter pack. #49

Closed
wants to merge 1 commit 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
21 changes: 10 additions & 11 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2929,22 +2929,21 @@ namespace {

static void CopyTypeConstraintFromAutoType(Sema &SemaRef, const AutoType *Auto,
TemplateTypeParmDecl *TP,
const bool IsParameterPack) {
TypeSourceInfo *DI =
SemaRef.getASTContext().getTrivialTypeSourceInfo(QualType(Auto, 0));
const Declarator &D) {
TypeSourceInfo *DI = SemaRef.getASTContext().getTrivialTypeSourceInfo(
QualType(Auto, 0), D.getBeginLoc());
const AutoTypeLoc ATL = DI->getTypeLoc().findAutoTypeLoc();

TemplateArgumentListInfo TAL(ATL.getLAngleLoc(), ATL.getRAngleLoc());
for (unsigned Idx = 0; Idx < ATL.getNumArgs(); ++Idx) {
TAL.addArgument(ATL.getArgLoc(Idx));
}

if (ATL.wereArgumentsSpecified())
for (unsigned Idx = 0, C = ATL.getNumArgs(); Idx != C; ++Idx)
TAL.addArgument(ATL.getArgLoc(Idx));

SemaRef.AttachTypeConstraint(
ATL.getNestedNameSpecifierLoc(), ATL.getConceptNameInfo(),
ATL.getNamedConcept(), ATL.wereArgumentsSpecified() ? &TAL : nullptr, TP,
IsParameterPack
? DI->getTypeLoc().getAs<PackExpansionTypeLoc>().getEllipsisLoc()
: SourceLocation());
D.hasEllipsis() ? D.getEllipsisLoc() : SourceLocation());
}

static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
Expand Down Expand Up @@ -3061,8 +3060,8 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,

// Attach type constraints
if (Auto->isConstrained())
CopyTypeConstraintFromAutoType(
SemaRef, Auto, CorrespondingTemplateParam, IsParameterPack);
CopyTypeConstraintFromAutoType(SemaRef, Auto,
CorrespondingTemplateParam, D);

// Replace the 'auto' in the function parameter with this invented
// template type parameter.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s

template<typename>
concept One = true;
// expected-note@-1 {{template is declared here}}

template<typename, typename>
concept Two = true;
// expected-note@-1 3{{template is declared here}}

auto acc_1 = [](One auto) { return 0; };
auto rej_1 = [](One<int> auto) { return 0; };
// expected-error@-1 {{too many template arguments for concept}}
auto rej_2_1 = [](Two auto) { return 0; };
// expected-error@-1 {{too few template arguments for concept}}
auto acc_2_1 = [](Two<int> auto) { return 0; };
auto rej_2_2 = [](Two<int, int> auto) { return 0; };
// expected-error@-1 {{too many template arguments for concept}}
auto rej_2_3 = [](Two<int, int, int> auto) { return 0; };
// expected-error@-1 {{too many template arguments for concept}}

template<typename T, unsigned Size>
concept LargerThan = sizeof(T) > Size;
// expected-note@-1 3{{because 'sizeof(char) > 1U' (1 > 1) evaluated to false}}

template<typename T>
concept Large = LargerThan<T, 1>;
// expected-note@-1 3{{because 'LargerThan<char, 1>' evaluated to false}}

auto l1 = [](Large auto l) { return l; };
// expected-note@-1{{candidate template ignored: constraints not satisfied [with l:auto = char]}}
// expected-note@-2{{because 'char' does not satisfy 'Large'}}
auto l1t1 = l1('a');
// expected-error@-1{{no matching function for call to object of type '(lambda at}}
auto l1t2 = l1(1);

auto l2 = [](Large auto ...ls) { return 0; };
// expected-note@-1{{candidate template ignored: constraints not satisfied [with ls:auto = <char>]}}
// expected-note@-2{{candidate template ignored: constraints not satisfied [with ls:auto = <int, char>]}}
// expected-note@-3 2{{because 'char' does not satisfy 'Large'}}
auto l2t1 = l2('a');
// expected-error@-1{{no matching function for call to object of type '(lambda at}}
auto l2t2 = l2(1, 'a');
// expected-error@-1{{no matching function for call to object of type '(lambda at}}
auto l2t3 = l2(1, 2);