File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
16538
16538
}
16539
16539
}
16540
16540
16541
+ // Complain if we are converting a lambda expression to a boolean value
16542
+ if (auto *MCallExpr = dyn_cast<CXXMemberCallExpr>(E)) {
16543
+ if (MCallExpr->getObjectType()->isRecordType()) {
16544
+ if (auto *MRecordDecl = MCallExpr->getRecordDecl()) {
16545
+ if (MRecordDecl->isLambda()) {
16546
+ std::string Str;
16547
+ llvm::raw_string_ostream S(Str);
16548
+ const unsigned DiagID = diag::warn_impcast_pointer_to_bool;
16549
+ // For lambdas, the pointer type is function, which corresponds to 1.
16550
+ const unsigned FunctionPointerType = 1;
16551
+ // Pretty print the diagnostic for the warning
16552
+ E->printPretty(S, nullptr, getPrintingPolicy());
16553
+ Diag(E->getExprLoc(), DiagID)
16554
+ << FunctionPointerType << S.str() << E->getSourceRange() << Range
16555
+ << IsEqual;
16556
+ return;
16557
+ }
16558
+ }
16559
+ }
16560
+ }
16561
+
16541
16562
// Expect to find a single Decl. Skip anything more complicated.
16542
16563
ValueDecl *D = nullptr;
16543
16564
if (DeclRefExpr *R = dyn_cast<DeclRefExpr>(E)) {
You can’t perform that action at this time.
0 commit comments