Skip to content

Commit baeace1

Browse files
committed
[clang] Factor out isCapturelessLambda
This changes the behavior of the call-site in "CodeGenFunction.cpp", I think for the better. But I couldn't figure out how to test that codepath.
1 parent 0c4a81f commit baeace1

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

clang/include/clang/AST/DeclCXX.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,12 @@ class CXXRecordDecl : public RecordDecl {
10521052
return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
10531053
}
10541054

1055+
bool isCapturelessLambda() const {
1056+
if (!isLambda())
1057+
return false;
1058+
return getLambdaCaptureDefault() == LCD_None && capture_size() == 0;
1059+
}
1060+
10551061
/// Set the captures for this lambda closure type.
10561062
void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures);
10571063

clang/lib/AST/DeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ bool CXXRecordDecl::lambdaIsDefaultConstructibleAndAssignable() const {
686686
// C++17 [expr.prim.lambda]p21:
687687
// The closure type associated with a lambda-expression has no default
688688
// constructor and a deleted copy assignment operator.
689-
if (getLambdaCaptureDefault() != LCD_None || capture_size() != 0)
689+
if (!isCapturelessLambda())
690690
return false;
691691
return getASTContext().getLangOpts().CPlusPlus20;
692692
}

clang/lib/AST/Type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,8 +2664,7 @@ HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
26642664
if (Decl->isUnion())
26652665
return false;
26662666
if (Decl->isLambda())
2667-
return Decl->captures().empty() &&
2668-
(Decl->getLambdaCaptureDefault() == LCD_None);
2667+
return Decl->isCapturelessLambda();
26692668

26702669
auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
26712670
return Function->getOverloadedOperator() ==

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,11 +1216,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
12161216
SkippedChecks.set(SanitizerKind::ObjectSize, true);
12171217
QualType ThisTy = MD->getThisType();
12181218

1219-
// If this is the call operator of a lambda with no capture-default, it
1219+
// If this is the call operator of a lambda with no captures, it
12201220
// may have a static invoker function, which may call this operator with
12211221
// a null 'this' pointer.
1222-
if (isLambdaCallOperator(MD) &&
1223-
MD->getParent()->getLambdaCaptureDefault() == LCD_None)
1222+
if (isLambdaCallOperator(MD) && MD->getParent()->isCapturelessLambda())
12241223
SkippedChecks.set(SanitizerKind::Null, true);
12251224

12261225
EmitTypeCheck(

clang/lib/Sema/SemaLambda.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ void Sema::DiagnoseInvalidExplicitObjectParameterInLambda(
393393
CXXRecordDecl *RD = Method->getParent();
394394
if (Method->getType()->isDependentType())
395395
return;
396-
if (RD->getLambdaCaptureDefault() == LambdaCaptureDefault::LCD_None &&
397-
RD->capture_size() == 0)
396+
if (RD->isCapturelessLambda())
398397
return;
399398
QualType ExplicitObjectParameterType = Method->getParamDecl(0)
400399
->getType()

0 commit comments

Comments
 (0)