Quuxplusone added inline comments.

================
Comment at: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp:63-79
+static clang::CharSourceRange getReplaceRange(const CStyleCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(
+      CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getBeginLoc());
+}
+
+static clang::CharSourceRange
+getReplaceRange(const CXXFunctionalCastExpr *CastExpr) {
----------------
Ditto here:
```
static clang::CharSourceRange
getReplaceRange(const ExplicitCastExpr *Expr) {
  if (const auto *CastExpr = dyn_cast<CStyleCastExpr>(Expr)) {
    return CharSourceRange::getCharRange(
        CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getBeginLoc());
  } else if (const auto *CastExpr = dyn_cast<CXXFunctionalCastExpr>(Expr)) {
    return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
                                         CastExpr->getLParenLoc());
  } else {
    // however Clang spells "unreachable"
  }
}
```
Besides saving some reader-brain-cells, this also makes it clearer that there's 
a potential null dereference in the old code (if both `dyn_cast`s fail) that 
we're hoping is unreachable. This way, we have a place we can annotate that 
with `assert(false)` or whatever, instead of just dereferencing null.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114427/new/

https://reviews.llvm.org/D114427

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to