[PATCH] D99646: [clang-tidy] misc-avoid-std-io-outside-main: a new check

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 3 03:17:34 PDT 2021


njames93 added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/misc/AvoidStdIoOutsideMainCheck.cpp:22
+  Finder->addMatcher(
+      declRefExpr(to(varDecl(hasAnyName("cin", "wcin", "cout", "wcout", "cerr",
+                                        "wcerr"),
----------------
mgartmann wrote:
> Would there be a way to extract these names (`cin`, `cout`, ...) into a separate variable? In my opinion, this would make the AST matchers cleaner and easier to read.
> 
> E.g., I was not able to find an overload of `hasAnyName()` which takes a `std:.vector` as argument.
> 
> Looking forward to hearing from you.
> Thanks for any feedback in advance.
`hasAnyName` can take an `ArrayRef<StringRef>` So If you have a `std::vector<StringRef>` that would work. If you have `std::vector<std::string>` you can still sort of use it
```lang=c++
  auto StringClassMatcher = cxxRecordDecl(hasAnyName(SmallVector<StringRef, 4>(
      StringLikeClasses.begin(), StringLikeClasses.end())));```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99646



More information about the cfe-commits mailing list