[PATCH] D45927: [clang-tidy] [modernize-use-auto] Correct way to calculate a type name length for multi-token types

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 30 08:10:53 PDT 2018


alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.


================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:33
+
+bool IsNotSpace(const char& C) {
+  return !std::isspace(static_cast<unsigned char>(C));
----------------
Why `const char&` and not just `char`? Moreover, these two functions can be replaced with lambdas. See below.


================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:445-449
+size_t UseAutoCheck::GetTypeNameLength(const SourceRange &SR,
+                                       const ASTContext &Context) {
+  const StringRef S = tooling::fixit::getText(SR, Context);
+  return std::count_if(S.begin(), S.end(), SpacePredicate);
+}
----------------
```
static size_t GetTypeNameLength(const TypeLoc &Loc, const ASTContext &Context, bool IgnoreStars) {
  const StringRef S = tooling::fixit::getText(Loc.getSourceRange(), Context);
  if (IgnoreStars)
    return llvm::count_if(S, [] (char C) { return std::isspace(C) || C == '*'; });
  return llvm::count_if(S, [] (char C) { return std::isspace(C); });
}
```


================
Comment at: clang-tidy/modernize/UseAutoCheck.h:31
                    StringRef Message);
+  size_t GetTypeNameLength(const SourceRange &SR, const ASTContext &Context);
 
----------------
I'd make this a static function and remove the `SpacePredicate` field as well. See the comment below.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45927





More information about the cfe-commits mailing list