[PATCH] D124341: [clang-tidy][NFC] Replace many instances of std::string where a StringRef would suffice.

Richard via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 14 11:56:12 PDT 2022


LegalizeAdulthood added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.cpp:56
 ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
-  const auto &Iter = CheckOptions.find(NamePrefix + LocalName.str());
+  const auto &Iter = CheckOptions.find((NamePrefix + LocalName).str());
   if (Iter != CheckOptions.end())
----------------
njames93 wrote:
> LegalizeAdulthood wrote:
> > `find` takes a `StringRef` so why convert to `std::string` here?
> Because a concatenation of StringRef results in a Twine, which cannot be passed to find.
Interactions between `std::string`, `StringRef` and `Twine` always make my brain hurt `:)`.

I keep wondering if there's a way to make `StringRef` and `Twine` more user-friendly, or perhaps a clang-tidy check that will alert you to things  that are "considered harmful".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124341



More information about the cfe-commits mailing list