[PATCH] D52281: [clang-tidy] Add modernize check to use std::invoke in generic code

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 24 13:59:03 PDT 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/modernize/ReplaceGenericFunctorCallCheck.cpp:70
+  if (MFunctor && MFunctor->isTypeDependent()) {
+    const auto *Paren = static_cast<const ParenExpr *>(MFunctor->getCallee());
+    const auto *BinOp =
----------------
JonasToth wrote:
> Eugene.Zelenko wrote:
> > I think you should use LLVM's cast instead, but I'm not sure which one. Same for other places.
> in this case i think `const auto *BinOp = dyn_cast<BinaryOperator>(Paren->getSubExpr());` would match.
> 
> As a safety measure adding a `assert(BinOp && "No Binary Operator as subexpression");` helps spotting bugs.
I agree; you'd want `dyn_cast` here. There's no need to add that assertion -- `dyn_cast` already asserts that the given value is non-null. If the value could be null and still be valid, you could use `dyn_cast_or_null` instead.


https://reviews.llvm.org/D52281





More information about the cfe-commits mailing list