================ @@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E, } } + // Complain if we are converting a lambda expression to a boolean value + if (const auto *MCallExpr = dyn_cast<CXXMemberCallExpr>(E)) { + if (MCallExpr->getObjectType()->isRecordType()) { + if (const auto *MRecordDecl = MCallExpr->getRecordDecl()) { + if (MRecordDecl->isLambda()) { + std::string Str; + llvm::raw_string_ostream S(Str); + + E->printPretty(S, nullptr, getPrintingPolicy()); + Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool) + << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange() + << Range << IsEqual; + return; + } + } + } + } ---------------- vinayakdsci wrote:
That is actually a great idea! and then the diagnostic would simply say address of lambda function {..} will always evaluate to true. Would actually be more informative than printing the entire expression in my opinion. Should I modify the code to do this instead?? https://github.com/llvm/llvm-project/pull/83152 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits