Skip to content

Commit c355082

Browse files
authored
Update SemaLambda.cpp
1 parent ffd9f20 commit c355082

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

clang/lib/Sema/SemaLambda.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,20 +1164,26 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
11641164
CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
11651165
/*FunctionScopeIndexToStopAtPtr*/ nullptr,
11661166
C->Kind == LCK_StarThis);
1167-
if (!LSI->Captures.empty())
1168-
{
1169-
SourceManager &SourceMgr = Context.getSourceManager();
1170-
const LangOptions &LangOpts = Context.getLangOpts();
1171-
SourceRange TrimmedRange = Lexer::makeFileCharRange(
1172-
CharSourceRange::getTokenRange(C->ExplicitRange), SourceMgr, LangOpts).getAsRange();
1173-
LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
1174-
}
1167+
if (!LSI->Captures.empty()) { //
1168+
SourceManager &SourceMgr = Context.getSourceManager();
1169+
const LangOptions &LangOpts = Context.getLangOpts();
1170+
SourceRange TrimmedRange = Lexer::makeFileCharRange(
1171+
CharSourceRange::getTokenRange(C->ExplicitRange), SourceMgr, LangOpts)
1172+
.getAsRange();
1173+
LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
1174+
}
1175+
continue; // // skip further processing for `this` and `*this` captures.
11751176
}
11761177

1177-
assert(C->Id && "missing identifier for capture");
1178+
if (!C->Id) { //
1179+
Diag(C->Loc, diag::err_expected_identifier_for_lambda_capture); //
1180+
continue; //
1181+
}
11781182

1179-
if (C->Init.isInvalid())
1180-
continue;
1183+
if (C->Init.isInvalid()) {
1184+
Diag(C->Loc, diag::err_invalid_lambda_capture_initializer_type); //
1185+
continue; //
1186+
}
11811187

11821188
ValueDecl *Var = nullptr;
11831189
if (C->Init.isUsable()) {
@@ -1190,8 +1196,10 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
11901196
// for e.g., [n{0}] { }; <-- if no <initializer_list> is included.
11911197
// FIXME: we should create the init capture variable and mark it invalid
11921198
// in this case.
1193-
if (C->InitCaptureType.get().isNull())
1194-
continue;
1199+
if (C->InitCaptureType.get().isNull() && !C->Init.isUsable()) {
1200+
Diag(C->Loc, diag::err_invalid_lambda_capture_initializer_type); //
1201+
continue; //
1202+
}
11951203

11961204
if (C->Init.get()->containsUnexpandedParameterPack() &&
11971205
!C->InitCaptureType.get()->getAs<PackExpansionType>())

0 commit comments

Comments
 (0)