diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h @@ -155,14 +155,14 @@ /// Reads the option with the check-local name \p LocalName from the /// ``CheckOptions``. If the corresponding key is not present, return /// ``None``. - llvm::Optional get(StringRef LocalName) const; + llvm::Optional get(StringRef LocalName) const; /// Read a named option from the ``Context``. /// /// Reads the option with the check-local name \p LocalName from the /// ``CheckOptions``. If the corresponding key is not present, returns /// \p Default. - std::string get(StringRef LocalName, StringRef Default) const; + StringRef get(StringRef LocalName, StringRef Default) const; /// Read a named option from the ``Context``. /// @@ -170,7 +170,7 @@ /// global ``CheckOptions``. Gets local option first. If local is not /// present, falls back to get global option. If global option is not /// present either, return ``None``. - llvm::Optional getLocalOrGlobal(StringRef LocalName) const; + llvm::Optional getLocalOrGlobal(StringRef LocalName) const; /// Read a named option from the ``Context``. /// @@ -178,7 +178,7 @@ /// global ``CheckOptions``. Gets local option first. If local is not /// present, falls back to get global option. If global option is not /// present either, returns \p Default. - std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const; + StringRef getLocalOrGlobal(StringRef LocalName, StringRef Default) const; /// Read a named option from the ``Context`` and parse it as an /// integral type ``T``. @@ -192,7 +192,7 @@ template std::enable_if_t::value, llvm::Optional> get(StringRef LocalName) const { - if (llvm::Optional Value = get(LocalName)) { + if (llvm::Optional Value = get(LocalName)) { T Result{}; if (!StringRef(*Value).getAsInteger(10, Result)) return Result; @@ -229,7 +229,7 @@ template std::enable_if_t::value, llvm::Optional> getLocalOrGlobal(StringRef LocalName) const { - llvm::Optional ValueOr = get(LocalName); + llvm::Optional ValueOr = get(LocalName); bool IsGlobal = false; if (!ValueOr) { IsGlobal = true; diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -48,14 +48,14 @@ ClangTidyCheck::OptionsView::OptionsView( StringRef CheckName, const ClangTidyOptions::OptionMap &CheckOptions, ClangTidyContext *Context) - : NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions), + : NamePrefix((CheckName + ".").str()), CheckOptions(CheckOptions), Context(Context) {} -llvm::Optional +llvm::Optional 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()) - return Iter->getValue().Value; + return StringRef(Iter->getValue().Value); return None; } @@ -63,7 +63,7 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options, StringRef NamePrefix, StringRef LocalName) { auto IterLocal = Options.find((NamePrefix + LocalName).str()); - auto IterGlobal = Options.find(LocalName.str()); + auto IterGlobal = Options.find(LocalName); if (IterLocal == Options.end()) return IterGlobal; if (IterGlobal == Options.end()) @@ -73,11 +73,11 @@ return IterGlobal; } -llvm::Optional +llvm::Optional ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const { auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName); if (Iter != CheckOptions.end()) - return Iter->getValue().Value; + return StringRef(Iter->getValue().Value); return None; } @@ -97,7 +97,7 @@ template <> llvm::Optional ClangTidyCheck::OptionsView::get(StringRef LocalName) const { - if (llvm::Optional ValueOr = get(LocalName)) { + if (llvm::Optional ValueOr = get(LocalName)) { if (auto Result = getAsBool(*ValueOr, NamePrefix + LocalName)) return Result; diagnoseBadBooleanOption(NamePrefix + LocalName, *ValueOr); @@ -120,7 +120,7 @@ void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const { - Options[NamePrefix + LocalName.str()] = Value; + Options[(NamePrefix + LocalName).str()] = Value; } void ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options, @@ -167,10 +167,9 @@ } } if (EditDistance < 3) - diagnoseBadEnumOption(Iter->getKey().str(), Iter->getValue().Value, - Closest); + diagnoseBadEnumOption(Iter->getKey(), Iter->getValue().Value, Closest); else - diagnoseBadEnumOption(Iter->getKey().str(), Iter->getValue().Value); + diagnoseBadEnumOption(Iter->getKey(), Iter->getValue().Value); return None; } @@ -203,18 +202,15 @@ Diag << 3 << Suggestion; } -std::string ClangTidyCheck::OptionsView::get(StringRef LocalName, - StringRef Default) const { - if (llvm::Optional Val = get(LocalName)) - return std::move(*Val); - return Default.str(); +StringRef ClangTidyCheck::OptionsView::get(StringRef LocalName, + StringRef Default) const { + return get(LocalName).getValueOr(Default); } -std::string + +StringRef ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName, StringRef Default) const { - if (llvm::Optional Val = getLocalOrGlobal(LocalName)) - return std::move(*Val); - return Default.str(); + return getLocalOrGlobal(LocalName).getValueOr(Default); } } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h --- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h @@ -35,9 +35,9 @@ void storeOptions(ClangTidyOptions::OptionMap &Opts) override; private: - const std::vector StringLikeClasses; + const std::vector StringLikeClasses; utils::IncludeInserter IncludeInserter; - const std::string AbseilStringsMatchHeader; + const StringRef AbseilStringsMatchHeader; }; } // namespace abseil diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp --- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp @@ -34,8 +34,7 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) { auto ZeroLiteral = integerLiteral(equals(0)); - auto StringClassMatcher = cxxRecordDecl(hasAnyName(SmallVector( - StringLikeClasses.begin(), StringLikeClasses.end()))); + auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses)); auto StringType = hasUnqualifiedDesugaredType( recordType(hasDeclaration(StringClassMatcher))); diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h --- a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h @@ -28,8 +28,8 @@ void storeOptions(ClangTidyOptions::OptionMap &Opts) override; private: - const std::vector StringLikeClassesOption; - const std::string AbseilStringsMatchHeaderOption; + const std::vector StringLikeClassesOption; + const StringRef AbseilStringsMatchHeaderOption; }; } // namespace abseil diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp --- a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp @@ -40,10 +40,9 @@ static const char DefaultAbseilStringsMatchHeader[] = "absl/strings/match.h"; static transformer::RewriteRuleWith -makeRewriteRule(const std::vector &StringLikeClassNames, +makeRewriteRule(ArrayRef StringLikeClassNames, StringRef AbseilStringsMatchHeader) { - auto StringLikeClass = cxxRecordDecl(hasAnyName(SmallVector( - StringLikeClassNames.begin(), StringLikeClassNames.end()))); + auto StringLikeClass = cxxRecordDecl(hasAnyName(StringLikeClassNames)); auto StringType = hasUnqualifiedDesugaredType(recordType(hasDeclaration(StringLikeClass))); auto CharStarType = diff --git a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h --- a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h +++ b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h @@ -31,7 +31,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string RawRetryList; + const StringRef RawRetryList; SmallVector RetryMacros; }; diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.h @@ -40,9 +40,9 @@ private: const bool CheckFunctionCalls; - const std::string RawAssertList; + const StringRef RawAssertList; SmallVector AssertMacros; - const std::vector IgnoredFunctions; + const std::vector IgnoredFunctions; }; } // namespace bugprone diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp @@ -78,8 +78,8 @@ : ClangTidyCheck(Name, Context), CheckFunctionCalls(Options.get("CheckFunctionCalls", false)), RawAssertList(Options.get("AssertMacros", "assert,NSAssert,NSCAssert")), - IgnoredFunctions(utils::options::parseStringList( - "__builtin_expect;" + Options.get("IgnoredFunctions", ""))) { + IgnoredFunctions(utils::options::parseListPair( + "__builtin_expect;", Options.get("IgnoredFunctions", ""))) { StringRef(RawAssertList).split(AssertMacros, ",", -1, false); } diff --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h @@ -31,7 +31,7 @@ void registerMatchersForVariables(ast_matchers::MatchFinder *Finder); void registerMatchersForReturn(ast_matchers::MatchFinder *Finder); - const std::vector HandleClasses; + const std::vector HandleClasses; const ast_matchers::internal::Matcher IsAHandle; }; diff --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp @@ -94,9 +94,7 @@ HandleClasses(utils::options::parseStringList(Options.get( "HandleClasses", "std::basic_string_view;std::experimental::basic_string_view"))), - IsAHandle(cxxRecordDecl(hasAnyName(std::vector( - HandleClasses.begin(), HandleClasses.end()))) - .bind("handle")) {} + IsAHandle(cxxRecordDecl(hasAnyName(HandleClasses)).bind("handle")) {} void DanglingHandleCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "HandleClasses", diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h @@ -36,7 +36,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string RawStringHeaderFileExtensions; + const StringRef RawStringHeaderFileExtensions; utils::FileExtensionsSet HeaderFileExtensions; }; diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h @@ -33,11 +33,11 @@ const std::size_t MinimumLength; /// The parameter names (as written in the source text) to be ignored. - const std::vector IgnoredParameterNames; + const std::vector IgnoredParameterNames; /// The parameter typename suffixes (as written in the source code) to be /// ignored. - const std::vector IgnoredParameterTypeSuffixes; + const std::vector IgnoredParameterTypeSuffixes; /// Whether to consider differently qualified versions of the same type /// mixable. diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp @@ -1552,7 +1552,7 @@ LLVM_DEBUG(llvm::dbgs() << "\tType name is '" << NodeTypeName << "'\n"); if (!NodeTypeName.empty()) { if (llvm::any_of(Check.IgnoredParameterTypeSuffixes, - [NodeTypeName](const std::string &E) { + [NodeTypeName](StringRef E) { return !E.empty() && NodeTypeName.endswith(E); })) { LLVM_DEBUG(llvm::dbgs() << "\tType suffix ignored.\n"); diff --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h @@ -32,7 +32,7 @@ /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-reserved-identifier.html class ReservedIdentifierCheck final : public RenamerClangTidyCheck { const bool Invert; - const std::vector AllowedIdentifiers; + const std::vector AllowedIdentifiers; public: ReservedIdentifierCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp @@ -109,7 +109,7 @@ static Optional getFailureInfoImpl(StringRef Name, bool IsInGlobalNamespace, const LangOptions &LangOpts, bool Invert, - ArrayRef AllowedIdentifiers) { + ArrayRef AllowedIdentifiers) { assert(!Name.empty()); if (llvm::is_contained(AllowedIdentifiers, Name)) return None; diff --git a/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.h b/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.h @@ -37,7 +37,7 @@ const ast_matchers::internal::Matcher &IntegerType, const std::string &CastBindName) const; - const std::string CharTypdefsToIgnoreList; + const StringRef CharTypdefsToIgnoreList; const bool DiagnoseSignedUnsignedCharComparisons; }; diff --git a/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp @@ -20,12 +20,6 @@ static constexpr int UnsignedASCIIUpperBound = 127; -static Matcher hasAnyListedName(const std::string &Names) { - const std::vector NameList = - utils::options::parseStringList(Names); - return hasAnyName(std::vector(NameList.begin(), NameList.end())); -} - SignedCharMisuseCheck::SignedCharMisuseCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), @@ -46,8 +40,8 @@ // We can ignore typedefs which are some kind of integer types // (e.g. typedef char sal_Int8). In this case, we don't need to // worry about the misinterpretation of char values. - const auto IntTypedef = qualType( - hasDeclaration(typedefDecl(hasAnyListedName(CharTypdefsToIgnoreList)))); + const auto IntTypedef = qualType(hasDeclaration(typedefDecl( + hasAnyName(utils::options::parseStringList(CharTypdefsToIgnoreList))))); auto CharTypeExpr = expr(); if (IsSigned) { diff --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h @@ -33,7 +33,7 @@ const bool IsStringviewNullptrCheckEnabled; const bool WarnOnLargeLength; const unsigned int LargeLengthThreshold; - std::vector StringNames; + std::vector StringNames; }; } // namespace bugprone diff --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp @@ -27,7 +27,7 @@ "::std::basic_string;::std::basic_string_view"; static std::vector -removeNamespaces(const std::vector &Names) { +removeNamespaces(const std::vector &Names) { std::vector Result; Result.reserve(Names.size()); for (StringRef Name : Names) { diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h @@ -46,8 +46,8 @@ utils::FileExtensionsSet ImplementationFileExtensions; private: - const std::string RawStringHeaderFileExtensions; - const std::string RawStringImplementationFileExtensions; + const StringRef RawStringHeaderFileExtensions; + const StringRef RawStringImplementationFileExtensions; }; } // namespace bugprone diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMissingCommaCheck.cpp @@ -73,7 +73,7 @@ StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), SizeThreshold(Options.get("SizeThreshold", 5U)), - RatioThreshold(std::stod(Options.get("RatioThreshold", ".2"))), + RatioThreshold(std::stod(Options.get("RatioThreshold", ".2").str())), MaxConcatenatedTokens(Options.get("MaxConcatenatedTokens", 5U)) {} void SuspiciousMissingCommaCheck::storeOptions( diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.h b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.h @@ -29,7 +29,7 @@ private: const bool WarnOnImplicitComparison; const bool WarnOnLogicalNotComparison; - const std::string StringCompareLikeFunctions; + const StringRef StringCompareLikeFunctions; }; } // namespace bugprone diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp @@ -91,15 +91,12 @@ // Add the list of known string compare-like functions and add user-defined // functions. - std::vector FunctionNames = utils::options::parseStringList( - (llvm::Twine(KnownStringCompareFunctions) + StringCompareLikeFunctions) - .str()); + std::vector FunctionNames = utils::options::parseListPair( + KnownStringCompareFunctions, StringCompareLikeFunctions); // Match a call to a string compare functions. const auto FunctionCompareDecl = - functionDecl(hasAnyName(std::vector(FunctionNames.begin(), - FunctionNames.end()))) - .bind("decl"); + functionDecl(hasAnyName(FunctionNames)).bind("decl"); const auto DirectStringCompareCallExpr = callExpr(hasDeclaration(FunctionCompareDecl)).bind("call"); const auto MacroStringCompareCallExpr = conditionalOperator(anyOf( diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp @@ -138,8 +138,7 @@ callExpr(callee(functionDecl( // Don't match void overloads of checked functions. unless(returns(voidType())), - isInstantiatedFrom(hasAnyName( - std::vector(FunVec.begin(), FunVec.end())))))) + isInstantiatedFrom(hasAnyName(FunVec))))) .bind("match")))); auto UnusedInCompoundStmt = diff --git a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h b/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h --- a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h +++ b/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h @@ -32,9 +32,9 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string MemSetNames; - const std::string MemCpyNames; - const std::string MemCmpNames; + const StringRef MemSetNames; + const StringRef MemCpyNames; + const StringRef MemCmpNames; }; } // namespace cert diff --git a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp b/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp --- a/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp +++ b/clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp @@ -30,10 +30,6 @@ AST_MATCHER(CXXRecordDecl, isTriviallyCopyable) { return Node.hasTrivialCopyAssignment() && Node.hasTrivialCopyConstructor(); } -AST_MATCHER_P(NamedDecl, hasAnyNameStdString, std::vector, - String) { - return ast_matchers::internal::HasNameMatcher(String).matchesNode(Node); -} } // namespace static const char BuiltinMemSet[] = "::std::memset;" @@ -56,19 +52,6 @@ "operator==", "operator!=", "operator<", "operator>", "operator<=", "operator>="}; -static std::vector parseStringListPair(StringRef LHS, - StringRef RHS) { - if (LHS.empty()) { - if (RHS.empty()) - return {}; - return utils::options::parseStringList(RHS); - } - if (RHS.empty()) - return utils::options::parseStringList(LHS); - llvm::SmallString<512> Buffer; - return utils::options::parseStringList((LHS + RHS).toStringRef(Buffer)); -} - NonTrivialTypesLibcMemoryCallsCheck::NonTrivialTypesLibcMemoryCallsCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), @@ -104,21 +87,21 @@ }; Finder->addMatcher( - callExpr(callee(namedDecl(hasAnyNameStdString( - parseStringListPair(BuiltinMemSet, MemSetNames)))), + callExpr(callee(namedDecl(hasAnyName( + utils::options::parseListPair(BuiltinMemSet, MemSetNames)))), ArgChecker(unless(isTriviallyDefaultConstructible()), expr(integerLiteral(equals(0))))) .bind("lazyConstruct"), this); Finder->addMatcher( - callExpr(callee(namedDecl(hasAnyNameStdString( - parseStringListPair(BuiltinMemCpy, MemCpyNames)))), + callExpr(callee(namedDecl(hasAnyName( + utils::options::parseListPair(BuiltinMemCpy, MemCpyNames)))), ArgChecker(unless(isTriviallyCopyable()), IsStructPointer())) .bind("lazyCopy"), this); Finder->addMatcher( - callExpr(callee(namedDecl(hasAnyNameStdString( - parseStringListPair(BuiltinMemCmp, MemCmpNames)))), + callExpr(callee(namedDecl(hasAnyName( + utils::options::parseListPair(BuiltinMemCmp, MemCmpNames)))), ArgChecker(hasMethod(hasAnyName(ComparisonOperators)), IsStructPointer())) .bind("lazyCompare"), diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h @@ -32,7 +32,7 @@ private: utils::IncludeInserter IncludeInserter; - const std::string MathHeader; + const StringRef MathHeader; }; } // namespace cppcoreguidelines diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h @@ -102,7 +102,7 @@ const bool WarnOnFloatingPointNarrowingConversion; const bool WarnWithinTemplateInstantiation; const bool WarnOnEquivalentBitWidth; - const std::string IgnoreConversionFromTypes; + const StringRef IgnoreConversionFromTypes; const bool PedanticMode; }; diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp @@ -24,13 +24,6 @@ namespace clang { namespace tidy { namespace cppcoreguidelines { -namespace { -auto hasAnyListedName(const std::string &Names) { - const std::vector NameList = - utils::options::parseStringList(Names); - return hasAnyName(std::vector(NameList.begin(), NameList.end())); -} -} // namespace NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name, ClangTidyContext *Context) @@ -79,8 +72,8 @@ // We may want to exclude other types from the checks, such as `size_type` // and `difference_type`. These are often used to count elements, represented // in 64 bits and assigned to `int`. Rarely are people counting >2B elements. - const auto IsConversionFromIgnoredType = - hasType(namedDecl(hasAnyListedName(IgnoreConversionFromTypes))); + const auto IsConversionFromIgnoredType = hasType(namedDecl( + hasAnyName(utils::options::parseStringList(IgnoreConversionFromTypes)))); // `IsConversionFromIgnoredType` will ignore narrowing calls from those types, // but not expressions that are promoted to an ignored type as a result of a diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.h @@ -47,13 +47,13 @@ private: /// Semicolon-separated list of fully qualified names of memory allocation /// functions the check warns about. Defaults to `::malloc;::calloc`. - const std::string AllocList; + const StringRef AllocList; /// Semicolon-separated list of fully qualified names of memory reallocation /// functions the check warns about. Defaults to `::realloc`. - const std::string ReallocList; + const StringRef ReallocList; /// Semicolon-separated list of fully qualified names of memory deallocation /// functions the check warns about. Defaults to `::free`. - const std::string DeallocList; + const StringRef DeallocList; }; } // namespace cppcoreguidelines diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp @@ -22,14 +22,6 @@ namespace tidy { namespace cppcoreguidelines { -namespace { -Matcher hasAnyListedName(const std::string &FunctionNames) { - const std::vector NameList = - utils::options::parseStringList(FunctionNames); - return hasAnyName(std::vector(NameList.begin(), NameList.end())); -} -} // namespace - void NoMallocCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "Allocations", AllocList); Options.store(Opts, "Reallocations", ReallocList); @@ -38,19 +30,22 @@ void NoMallocCheck::registerMatchers(MatchFinder *Finder) { // Registering malloc, will suggest RAII. - Finder->addMatcher(callExpr(callee(functionDecl(hasAnyListedName(AllocList)))) + Finder->addMatcher(callExpr(callee(functionDecl(hasAnyName( + utils::options::parseStringList(AllocList))))) .bind("allocation"), this); // Registering realloc calls, suggest std::vector or std::string. Finder->addMatcher( - callExpr(callee(functionDecl(hasAnyListedName(ReallocList)))) + callExpr(callee(functionDecl( + hasAnyName(utils::options::parseStringList((ReallocList)))))) .bind("realloc"), this); // Registering free calls, will suggest RAII instead. Finder->addMatcher( - callExpr(callee(functionDecl(hasAnyListedName(DeallocList)))) + callExpr(callee(functionDecl( + hasAnyName(utils::options::parseStringList((DeallocList)))))) .bind("free"), this); } diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h @@ -52,10 +52,10 @@ /// List of old C-style functions that create resources. /// Defaults to /// `::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`. - const std::string LegacyResourceProducers; + const StringRef LegacyResourceProducers; /// List of old C-style functions that consume or release resources. /// Defaults to `::free;::realloc;::freopen;::fclose`. - const std::string LegacyResourceConsumers; + const StringRef LegacyResourceConsumers; }; } // namespace cppcoreguidelines diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp @@ -21,16 +21,6 @@ namespace tidy { namespace cppcoreguidelines { -// FIXME: Copied from 'NoMallocCheck.cpp'. Has to be refactored into 'util' or -// something like that. -namespace { -Matcher hasAnyListedName(const std::string &FunctionNames) { - const std::vector NameList = - utils::options::parseStringList(FunctionNames); - return hasAnyName(std::vector(NameList.begin(), NameList.end())); -} -} // namespace - void OwningMemoryCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "LegacyResourceProducers", LegacyResourceProducers); Options.store(Opts, "LegacyResourceConsumers", LegacyResourceConsumers); @@ -42,9 +32,10 @@ const auto OwnerDecl = typeAliasTemplateDecl(hasName("::gsl::owner")); const auto IsOwnerType = hasType(OwnerDecl); - const auto LegacyCreatorFunctions = hasAnyListedName(LegacyResourceProducers); + const auto LegacyCreatorFunctions = + hasAnyName(utils::options::parseStringList(LegacyResourceProducers)); const auto LegacyConsumerFunctions = - hasAnyListedName(LegacyResourceConsumers); + hasAnyName(utils::options::parseStringList(LegacyResourceConsumers)); // Legacy functions that are use for resource management but cannot be // updated to use `gsl::owner<>`, like standard C memory management. diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.h @@ -22,7 +22,7 @@ /// For the user-facing documentation see: /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.html class ProBoundsConstantArrayIndexCheck : public ClangTidyCheck { - const std::string GslHeader; + const StringRef GslHeader; utils::IncludeInserter Inserter; public: diff --git a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h --- a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h +++ b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h @@ -38,7 +38,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string RawStringHeaderFileExtensions; + const StringRef RawStringHeaderFileExtensions; utils::FileExtensionsSet HeaderFileExtensions; }; diff --git a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.h b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.h --- a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.h +++ b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.h @@ -39,9 +39,9 @@ void storeOptions(ClangTidyOptions::OptionMap &Options) override; private: - const std::string UnsignedTypePrefix; - const std::string SignedTypePrefix; - const std::string TypeSuffix; + const StringRef UnsignedTypePrefix; + const StringRef SignedTypePrefix; + const StringRef TypeSuffix; std::unique_ptr IdentTable; }; diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h --- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h +++ b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h @@ -44,7 +44,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string RawStringHeaderFileExtensions; + const StringRef RawStringHeaderFileExtensions; utils::FileExtensionsSet HeaderFileExtensions; }; diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h --- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h +++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h @@ -43,7 +43,7 @@ private: const bool UseHeaderFileExtension; - const std::string RawStringHeaderFileExtensions; + const StringRef RawStringHeaderFileExtensions; utils::FileExtensionsSet HeaderFileExtensions; }; diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h @@ -177,7 +177,7 @@ class DeclFinderASTVisitor : public clang::RecursiveASTVisitor { public: - DeclFinderASTVisitor(const std::string &Name, + DeclFinderASTVisitor(const StringRef &Name, const StmtGeneratedVarNameMap *GeneratedDecls) : Name(Name), GeneratedDecls(GeneratedDecls), Found(false) {} diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h @@ -47,8 +47,8 @@ private: utils::IncludeInserter Inserter; - const std::string MakeSmartPtrFunctionHeader; - const std::string MakeSmartPtrFunctionName; + const StringRef MakeSmartPtrFunctionHeader; + const StringRef MakeSmartPtrFunctionName; const bool IgnoreMacros; const bool IgnoreDefaultInitialization; diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h b/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h --- a/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h @@ -49,10 +49,10 @@ Preprocessor *ModuleExpanderPP) override; void storeOptions(ClangTidyOptions::OptionMap &Opts) override; - const std::string &getMacroName() const { return MacroName; } + const StringRef &getMacroName() const { return MacroName; } private: - const std::string MacroName; + const StringRef MacroName; }; } // namespace modernize diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h --- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h @@ -36,10 +36,10 @@ private: const bool IgnoreImplicitConstructors; - const std::vector ContainersWithPushBack; - const std::vector SmartPointers; - const std::vector TupleTypes; - const std::vector TupleMakeFunctions; + const std::vector ContainersWithPushBack; + const std::vector SmartPointers; + const std::vector TupleTypes; + const std::vector TupleMakeFunctions; }; } // namespace modernize diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp @@ -50,15 +50,14 @@ // + match for emplace calls that should be replaced with insertion auto CallPushBack = cxxMemberCallExpr( hasDeclaration(functionDecl(hasName("push_back"))), - on(hasType(cxxRecordDecl(hasAnyName(SmallVector( - ContainersWithPushBack.begin(), ContainersWithPushBack.end())))))); + on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushBack))))); // We can't replace push_backs of smart pointer because // if emplacement fails (f.e. bad_alloc in vector) we will have leak of // passed pointer because smart pointer won't be constructed // (and destructed) as in push_back case. - auto IsCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName( - SmallVector(SmartPointers.begin(), SmartPointers.end()))))); + auto IsCtorOfSmartPtr = + hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(SmartPointers)))); // Bitfields binds only to consts and emplace_back take it by universal ref. auto BitFieldAsArgument = hasAnyArgument( @@ -91,19 +90,16 @@ auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr)); auto MakeTuple = ignoringImplicit( - callExpr( - callee(expr(ignoringImplicit(declRefExpr( - unless(hasExplicitTemplateArgs()), - to(functionDecl(hasAnyName(SmallVector( - TupleMakeFunctions.begin(), TupleMakeFunctions.end()))))))))) + callExpr(callee(expr(ignoringImplicit(declRefExpr( + unless(hasExplicitTemplateArgs()), + to(functionDecl(hasAnyName(TupleMakeFunctions)))))))) .bind("make")); // make_something can return type convertible to container's element type. // Allow the conversion only on containers of pairs. auto MakeTupleCtor = ignoringImplicit(cxxConstructExpr( has(materializeTemporaryExpr(MakeTuple)), - hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName( - SmallVector(TupleTypes.begin(), TupleTypes.end()))))))); + hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(TupleTypes)))))); auto SoughtParam = materializeTemporaryExpr( anyOf(has(MakeTuple), has(MakeTupleCtor), diff --git a/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.h --- a/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.h @@ -40,7 +40,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string NoDiscardMacro; + const StringRef NoDiscardMacro; }; } // namespace modernize diff --git a/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp @@ -131,7 +131,7 @@ // 1. A const member function which returns a variable which is ignored // but performs some external I/O operation and the return value could be // ignored. - Diag << FixItHint::CreateInsertion(RetLoc, NoDiscardMacro + " "); + Diag << FixItHint::CreateInsertion(RetLoc, (NoDiscardMacro + " ").str()); } bool UseNodiscardCheck::isLanguageVersionSupported( diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h --- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.h @@ -40,7 +40,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string NoexceptMacro; + const StringRef NoexceptMacro; const bool UseNoexceptFalse; }; diff --git a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNoexceptCheck.cpp @@ -89,12 +89,10 @@ bool IsNoThrow = FnTy->isNothrow(); StringRef ReplacementStr = - IsNoThrow - ? NoexceptMacro.empty() ? "noexcept" : NoexceptMacro.c_str() - : NoexceptMacro.empty() - ? (DtorOrOperatorDel || UseNoexceptFalse) ? "noexcept(false)" - : "" - : ""; + IsNoThrow ? NoexceptMacro.empty() ? "noexcept" : NoexceptMacro + : NoexceptMacro.empty() + ? (DtorOrOperatorDel || UseNoexceptFalse) ? "noexcept(false)" : "" + : ""; FixItHint FixIt; if ((IsNoThrow || NoexceptMacro.empty()) && CRange.isValid()) diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h @@ -28,7 +28,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - const std::string NullMacrosStr; + const StringRef NullMacrosStr; SmallVector NullMacros; }; diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h --- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h @@ -30,8 +30,8 @@ private: const bool IgnoreDestructors; const bool AllowOverrideAndFinal; - const std::string OverrideSpelling; - const std::string FinalSpelling; + const StringRef OverrideSpelling; + const StringRef FinalSpelling; }; } // namespace modernize diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp @@ -141,7 +141,7 @@ // Add 'override' on inline declarations that don't already have it. if (!HasFinal && !HasOverride) { SourceLocation InsertLoc; - std::string ReplacementText = OverrideSpelling + " "; + std::string ReplacementText = (OverrideSpelling + " ").str(); SourceLocation MethodLoc = Method->getLocation(); for (Token T : Tokens) { @@ -171,7 +171,7 @@ // end of the declaration of the function, but prefer to put it on the // same line as the declaration if the beginning brace for the start of // the body falls on the next line. - ReplacementText = " " + OverrideSpelling; + ReplacementText = (" " + OverrideSpelling).str(); auto *LastTokenIter = std::prev(Tokens.end()); // When try statement is used instead of compound statement as // method body - insert override keyword before it. @@ -192,14 +192,14 @@ InsertLoc = Tokens[Tokens.size() - 2].getLocation(); // Check if we need to insert a space. if ((Tokens[Tokens.size() - 2].getFlags() & Token::LeadingSpace) == 0) - ReplacementText = " " + OverrideSpelling + " "; + ReplacementText = (" " + OverrideSpelling + " ").str(); } else if (getText(Tokens.back(), Sources) == "ABSTRACT") InsertLoc = Tokens.back().getLocation(); } if (!InsertLoc.isValid()) { InsertLoc = FileRange.getEnd(); - ReplacementText = " " + OverrideSpelling; + ReplacementText = (" " + OverrideSpelling).str(); } // If the override macro has been specified just ensure it exists, diff --git a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h --- a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h +++ b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.h @@ -11,7 +11,6 @@ #include "../ClangTidyCheck.h" #include "llvm/ADT/StringRef.h" -#include #include namespace clang { @@ -34,7 +33,7 @@ void storeOptions(ClangTidyOptions::OptionMap &Options) override; private: - const std::vector ForbiddenSuperClassNames; + const std::vector ForbiddenSuperClassNames; }; } // namespace objc diff --git a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp --- a/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/ForbiddenSubclassingCheck.cpp @@ -51,14 +51,9 @@ void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( objcInterfaceDecl( - isDerivedFrom( - objcInterfaceDecl( - hasAnyName( - std::vector( - ForbiddenSuperClassNames.begin(), - ForbiddenSuperClassNames.end()))) - .bind("superclass"))) - .bind("subclass"), + isDerivedFrom(objcInterfaceDecl(hasAnyName(ForbiddenSuperClassNames)) + .bind("superclass"))) + .bind("subclass"), this); } diff --git a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h --- a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h +++ b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.h @@ -35,7 +35,7 @@ void storeOptions(ClangTidyOptions::OptionMap &Opts) override; private: - const std::vector StringLikeClasses; + const std::vector StringLikeClasses; }; } // namespace performance diff --git a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp --- a/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp @@ -71,11 +71,9 @@ callee(functionDecl(StringFindFunctions).bind("func")), anyOf(argumentCountIs(1), argumentCountIs(2)), hasArgument(0, SingleChar), - on(expr( - hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( - recordDecl(hasAnyName(SmallVector( - StringLikeClasses.begin(), StringLikeClasses.end()))))))), - unless(hasSubstitutedType())))), + on(expr(hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + recordDecl(hasAnyName(StringLikeClasses)))))), + unless(hasSubstitutedType())))), this); } diff --git a/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.h b/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.h --- a/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.h +++ b/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.h @@ -42,7 +42,7 @@ ASTContext &Context); const bool WarnOnAllAutoCopies; - const std::vector AllowedTypes; + const std::vector AllowedTypes; }; } // namespace performance diff --git a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h --- a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h +++ b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h @@ -38,7 +38,7 @@ StringRef VarDeclName, StringRef VarDeclStmtName, const ast_matchers::DeclarationMatcher &AppendMethodDecl, StringRef AppendCallName, ast_matchers::MatchFinder *Finder); - const std::vector VectorLikeClasses; + const std::vector VectorLikeClasses; // If true, also check inefficient operations for proto repeated fields. bool EnableProto; diff --git a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp --- a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp @@ -159,8 +159,7 @@ } void InefficientVectorOperationCheck::registerMatchers(MatchFinder *Finder) { - const auto VectorDecl = cxxRecordDecl(hasAnyName(SmallVector( - VectorLikeClasses.begin(), VectorLikeClasses.end()))); + const auto VectorDecl = cxxRecordDecl(hasAnyName(VectorLikeClasses)); const auto AppendMethodDecl = cxxMethodDecl(hasAnyName("push_back", "emplace_back")); addMatcher(VectorDecl, VectorVarDeclName, VectorVarDeclStmtName, diff --git a/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.h b/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.h --- a/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.h +++ b/clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.h @@ -29,7 +29,7 @@ void storeOptions(ClangTidyOptions::OptionMap &Opts) override; private: - const std::vector AllowedTypes; + const std::vector AllowedTypes; }; } // namespace performance diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h @@ -42,8 +42,8 @@ void handleCopyFromLocalVar(const VarDecl &NewVar, const VarDecl &OldVar, const Stmt &BlockStmt, const DeclStmt &Stmt, bool IssueFix, ASTContext &Context); - const std::vector AllowedTypes; - const std::vector ExcludedContainerTypes; + const std::vector AllowedTypes; + const std::vector ExcludedContainerTypes; }; } // namespace performance diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -76,7 +76,7 @@ } AST_MATCHER_FUNCTION_P(StatementMatcher, isConstRefReturningMethodCall, - std::vector, ExcludedContainerTypes) { + std::vector, ExcludedContainerTypes) { // Match method call expressions where the `this` argument is only used as // const, this will be checked in `check()` part. This returned const // reference is highly likely to outlive the local const reference of the @@ -110,7 +110,7 @@ } AST_MATCHER_FUNCTION_P(StatementMatcher, initializerReturnsReferenceToConst, - std::vector, ExcludedContainerTypes) { + std::vector, ExcludedContainerTypes) { auto OldVarDeclRef = declRefExpr(to(varDecl(hasLocalStorage()).bind(OldVarDeclId))); return expr( @@ -135,7 +135,7 @@ // object arg or variable that is referenced is immutable as well. static bool isInitializingVariableImmutable( const VarDecl &InitializingVar, const Stmt &BlockStmt, ASTContext &Context, - const std::vector &ExcludedContainerTypes) { + const std::vector &ExcludedContainerTypes) { if (!isOnlyUsedAsConst(InitializingVar, BlockStmt, Context)) return false; diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h @@ -42,7 +42,7 @@ llvm::DenseMap MutationAnalyzers; utils::IncludeInserter Inserter; - const std::vector AllowedTypes; + const std::vector AllowedTypes; }; } // namespace performance diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h @@ -198,7 +198,7 @@ mutable llvm::StringMap NamingStylesCache; FileStyle *MainFileStyle; ClangTidyContext *Context; - const std::string CheckName; + const StringRef CheckName; const bool GetConfigPerFile; const bool IgnoreFailedSplit; HungarianNotation HungarianNotation; diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -265,7 +265,7 @@ StyleString.resize(StyleSize); StyleString.append("IgnoredRegexp"); - std::string IgnoredRegexpStr = Options.get(StyleString, ""); + StringRef IgnoredRegexpStr = Options.get(StyleString, ""); StyleString.resize(StyleSize); StyleString.append("Prefix"); std::string Prefix(Options.get(StyleString, "")); @@ -281,7 +281,7 @@ if (CaseOptional || !Prefix.empty() || !Postfix.empty() || !IgnoredRegexpStr.empty() || HPTOpt) Styles[I].emplace(std::move(CaseOptional), std::move(Prefix), - std::move(Postfix), std::move(IgnoredRegexpStr), + std::move(Postfix), IgnoredRegexpStr.str(), HPTOpt.getValueOr(IdentifierNamingCheck::HPT_Off)); } bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false); @@ -445,16 +445,16 @@ SmallString<128> Buffer; for (const auto &Opt : HNOpts) { Buffer.assign({Section, "General.", Opt}); - std::string Val = Options.get(Buffer, ""); + StringRef Val = Options.get(Buffer, ""); if (!Val.empty()) - HNOption.General[Opt] = std::move(Val); + HNOption.General[Opt] = Val.str(); } for (const auto &Type : HNDerivedTypes) { Buffer.assign({Section, "DerivedType.", Type}); - std::string Val = Options.get(Buffer, ""); + StringRef Val = Options.get(Buffer, ""); if (!Val.empty()) - HNOption.DerivedType[Type] = std::move(Val); + HNOption.DerivedType[Type] = Val.str(); } static constexpr std::pair HNCStrings[] = { @@ -465,26 +465,26 @@ for (const auto &CStr : HNCStrings) { Buffer.assign({Section, "CString.", CStr.first}); - std::string Val = Options.get(Buffer, ""); + StringRef Val = Options.get(Buffer, ""); if (!Val.empty()) - HNOption.CString[CStr.first] = std::move(Val); + HNOption.CString[CStr.first] = Val.str(); } for (const auto &PrimType : HungarainNotationPrimitiveTypes) { Buffer.assign({Section, "PrimitiveType.", PrimType}); - std::string Val = Options.get(Buffer, ""); + StringRef Val = Options.get(Buffer, ""); if (!Val.empty()) { std::string Type = PrimType.str(); std::replace(Type.begin(), Type.end(), '-', ' '); - HNOption.PrimitiveType[Type] = std::move(Val); + HNOption.PrimitiveType[Type] = Val.str(); } } for (const auto &Type : HungarainNotationUserDefinedTypes) { Buffer.assign({Section, "UserDefinedType.", Type}); - std::string Val = Options.get(Buffer, ""); + StringRef Val = Options.get(Buffer, ""); if (!Val.empty()) - HNOption.UserDefinedType[Type] = std::move(Val); + HNOption.UserDefinedType[Type] = Val.str(); } } diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h --- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h +++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h @@ -86,8 +86,8 @@ const bool IgnoreAllFloatingPointValues; const bool IgnoreBitFieldsWidths; const bool IgnorePowersOf2IntegerValues; - const std::string RawIgnoredIntegerValues; - const std::string RawIgnoredFloatingPointValues; + const StringRef RawIgnoredIntegerValues; + const StringRef RawIgnoredFloatingPointValues; constexpr static unsigned SensibleNumberOfMagicValueExceptions = 16; diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp @@ -72,16 +72,20 @@ RawIgnoredFloatingPointValues(Options.get( "IgnoredFloatingPointValues", DefaultIgnoredFloatingPointValues)) { // Process the set of ignored integer values. - const std::vector IgnoredIntegerValuesInput = + const std::vector IgnoredIntegerValuesInput = utils::options::parseStringList(RawIgnoredIntegerValues); IgnoredIntegerValues.resize(IgnoredIntegerValuesInput.size()); llvm::transform(IgnoredIntegerValuesInput, IgnoredIntegerValues.begin(), - [](const std::string &Value) { return std::stoll(Value); }); + [](StringRef Value) { + int64_t Res; + Value.getAsInteger(10, Res); + return Res; + }); llvm::sort(IgnoredIntegerValues); if (!IgnoreAllFloatingPointValues) { // Process the set of ignored floating point values. - const std::vector IgnoredFloatingPointValuesInput = + const std::vector IgnoredFloatingPointValuesInput = utils::options::parseStringList(RawIgnoredFloatingPointValues); IgnoredFloatingPointValues.reserve(IgnoredFloatingPointValuesInput.size()); IgnoredDoublePointValues.reserve(IgnoredFloatingPointValuesInput.size()); diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h --- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h +++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h @@ -29,7 +29,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - std::vector StringNames; + std::vector StringNames; }; } // namespace readability diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp @@ -21,20 +21,13 @@ const char DefaultStringNames[] = "::std::basic_string_view;::std::basic_string"; -static ast_matchers::internal::Matcher -hasAnyNameStdString(std::vector Names) { - return ast_matchers::internal::Matcher( - new ast_matchers::internal::HasNameMatcher(std::move(Names))); -} - -static std::vector -removeNamespaces(const std::vector &Names) { - std::vector Result; +static std::vector removeNamespaces(ArrayRef Names) { + std::vector Result; Result.reserve(Names.size()); - for (const std::string &Name : Names) { - std::string::size_type ColonPos = Name.rfind(':'); + for (StringRef Name : Names) { + StringRef::size_type ColonPos = Name.rfind(':'); Result.push_back( - Name.substr(ColonPos == std::string::npos ? 0 : ColonPos + 1)); + Name.drop_front(ColonPos == StringRef::npos ? 0 : ColonPos + 1)); } return Result; } @@ -72,9 +65,8 @@ } void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) { - const auto HasStringTypeName = hasAnyNameStdString(StringNames); - const auto HasStringCtorName = - hasAnyNameStdString(removeNamespaces(StringNames)); + const auto HasStringTypeName = hasAnyName(StringNames); + const auto HasStringCtorName = hasAnyName(removeNamespaces(StringNames)); // Match string constructor. const auto StringConstructorExpr = expr( diff --git a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h --- a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h +++ b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h @@ -33,7 +33,7 @@ } private: - const std::vector Types; + const std::vector Types; }; } // namespace readability diff --git a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp @@ -28,8 +28,7 @@ void SimplifySubscriptExprCheck::registerMatchers(MatchFinder *Finder) { const auto TypesMatcher = hasUnqualifiedDesugaredType( - recordType(hasDeclaration(cxxRecordDecl(hasAnyName( - llvm::SmallVector(Types.begin(), Types.end())))))); + recordType(hasDeclaration(cxxRecordDecl(hasAnyName(Types))))); Finder->addMatcher( arraySubscriptExpr(hasBase( diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp @@ -526,12 +526,13 @@ GetBoundOpt(H, BoundKind::SimilarAbove))); } - for (const std::string &Abbreviation : optutils::parseStringList( + for (StringRef Abbreviation : optutils::parseStringList( Options.get("Abbreviations", DefaultAbbreviations))) { - auto KeyAndValue = StringRef{Abbreviation}.split("="); + auto KeyAndValue = Abbreviation.split("="); + llvm::errs() << "'" << Abbreviation << "'\n"; assert(!KeyAndValue.first.empty() && !KeyAndValue.second.empty()); AbbreviationDictionary.insert( - std::make_pair(KeyAndValue.first.str(), KeyAndValue.second.str())); + std::make_pair(KeyAndValue.first, KeyAndValue.second.str())); } } @@ -573,7 +574,8 @@ Abbreviations.emplace_back(EqualSignJoined.str()); } Options.store(Opts, "Abbreviations", - optutils::serializeStringList(Abbreviations)); + optutils::serializeStringList(std::vector( + Abbreviations.begin(), Abbreviations.end()))); } bool SuspiciousCallArgumentCheck::isHeuristicEnabled(Heuristic H) const { diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h --- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h +++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h @@ -36,7 +36,7 @@ template bool checkBoundMatch(const ast_matchers::MatchFinder::MatchResult &Result); - const std::vector NewSuffixes; + const std::vector NewSuffixes; const bool IgnoreMacros; }; diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp @@ -87,18 +87,18 @@ llvm::Optional getNewSuffix(llvm::StringRef OldSuffix, - const std::vector &NewSuffixes) { + const std::vector &NewSuffixes) { // If there is no config, just uppercase the entirety of the suffix. if (NewSuffixes.empty()) return OldSuffix.upper(); // Else, find matching suffix, case-*insensitive*ly. - auto NewSuffix = llvm::find_if( - NewSuffixes, [OldSuffix](const std::string &PotentialNewSuffix) { + auto NewSuffix = + llvm::find_if(NewSuffixes, [OldSuffix](StringRef PotentialNewSuffix) { return OldSuffix.equals_insensitive(PotentialNewSuffix); }); // Have a match, return it. if (NewSuffix != NewSuffixes.end()) - return *NewSuffix; + return NewSuffix->str(); // Nope, I guess we have to keep it as-is. return llvm::None; } @@ -106,7 +106,7 @@ template llvm::Optional shouldReplaceLiteralSuffix(const Expr &Literal, - const std::vector &NewSuffixes, + const std::vector &NewSuffixes, const SourceManager &SM, const LangOptions &LO) { NewSuffix ReplacementDsc; diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h --- a/clang-tools-extra/clang-tidy/utils/Matchers.h +++ b/clang-tools-extra/clang-tidy/utils/Matchers.h @@ -55,7 +55,7 @@ class MatchesAnyListedNameMatcher : public ast_matchers::internal::MatcherInterface { public: - explicit MatchesAnyListedNameMatcher(llvm::ArrayRef NameList) { + explicit MatchesAnyListedNameMatcher(llvm::ArrayRef NameList) { std::transform( NameList.begin(), NameList.end(), std::back_inserter(NameMatchers), [](const llvm::StringRef Name) { return NameMatcher(Name); }); @@ -116,7 +116,7 @@ // expressions. If a regular expression contains starts ':' the NamedDecl's // qualified name will be used for matching, otherwise its name will be used. inline ::clang::ast_matchers::internal::Matcher -matchesAnyListedName(llvm::ArrayRef NameList) { +matchesAnyListedName(llvm::ArrayRef NameList) { return ::clang::ast_matchers::internal::makeMatcher( new MatchesAnyListedNameMatcher(NameList)); } diff --git a/clang-tools-extra/clang-tidy/utils/OptionsUtils.h b/clang-tools-extra/clang-tidy/utils/OptionsUtils.h --- a/clang-tools-extra/clang-tidy/utils/OptionsUtils.h +++ b/clang-tools-extra/clang-tidy/utils/OptionsUtils.h @@ -9,7 +9,9 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OPTIONUTILS_H -#include "../ClangTidy.h" +#include "clang/Basic/LLVM.h" +#include +#include namespace clang { namespace tidy { @@ -17,11 +19,13 @@ namespace options { /// Parse a semicolon separated list of strings. -std::vector parseStringList(StringRef Option); +std::vector parseStringList(StringRef Option); + +std::vector parseListPair(StringRef L, StringRef R); /// Serialize a sequence of names that can be parsed by /// ``parseStringList``. -std::string serializeStringList(ArrayRef Strings); +std::string serializeStringList(ArrayRef Strings); } // namespace options } // namespace utils diff --git a/clang-tools-extra/clang-tidy/utils/OptionsUtils.cpp b/clang-tools-extra/clang-tidy/utils/OptionsUtils.cpp --- a/clang-tools-extra/clang-tidy/utils/OptionsUtils.cpp +++ b/clang-tools-extra/clang-tidy/utils/OptionsUtils.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "OptionsUtils.h" +#include "llvm/ADT/StringExtras.h" namespace clang { namespace tidy { @@ -15,19 +16,50 @@ static const char StringsDelimiter[] = ";"; -std::vector parseStringList(StringRef Option) { - SmallVector Names; - Option.split(Names, StringsDelimiter); - std::vector Result; - for (StringRef &Name : Names) { - Name = Name.trim(); - if (!Name.empty()) - Result.emplace_back(Name); +std::vector parseStringList(StringRef Option) { + Option = Option.trim().trim(StringsDelimiter); + if (Option.empty()) + return {}; + std::vector Result; + Result.reserve(Option.count(StringsDelimiter) + 1); + StringRef Cur; + while (std::tie(Cur, Option) = Option.split(StringsDelimiter), + !Option.empty()) { + Cur = Cur.trim(); + if (!Cur.empty()) + Result.push_back(Cur); } + Cur = Cur.trim(); + if (!Cur.empty()) + Result.push_back(Cur); return Result; } -std::string serializeStringList(ArrayRef Strings) { +std::vector parseListPair(StringRef L, StringRef R) { + L = L.trim().trim(StringsDelimiter); + if (L.empty()) + return parseStringList(R); + R = R.trim().trim(StringsDelimiter); + if (R.empty()) + return parseStringList(L); + std::vector Result; + Result.reserve(2 + L.count(StringsDelimiter) + R.count(StringsDelimiter)); + for (StringRef Option : {L, R}) { + StringRef Cur; + while (std::tie(Cur, Option) = Option.split(StringsDelimiter), + !Option.empty()) { + Cur = Cur.trim(); + if (!Cur.empty()) + Result.push_back(Cur); + } + Cur = Cur.trim(); + if (!Cur.empty()) + Result.push_back(Cur); + } + return Result; +} + +std::string serializeStringList(ArrayRef Strings) { return llvm::join(Strings, StringsDelimiter); } diff --git a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.h b/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.h --- a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.h +++ b/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.h @@ -31,7 +31,7 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - std::vector Names; + std::vector Names; }; } // namespace zircon diff --git a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp b/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp --- a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp +++ b/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp @@ -20,7 +20,7 @@ namespace tidy { namespace zircon { -AST_MATCHER_P(CXXRecordDecl, matchesAnyName, ArrayRef, Names) { +AST_MATCHER_P(CXXRecordDecl, matchesAnyName, ArrayRef, Names) { std::string QualifiedName = Node.getQualifiedNameAsString(); return llvm::any_of(Names, [&](StringRef Name) { return QualifiedName == Name; });