Index: change-namespace/ChangeNamespace.cpp =================================================================== --- change-namespace/ChangeNamespace.cpp +++ change-namespace/ChangeNamespace.cpp @@ -250,7 +250,10 @@ llvm::StringRef FallbackStyle) : FallbackStyle(FallbackStyle), FileToReplacements(*FileToReplacements), OldNamespace(OldNs.ltrim(':')), NewNamespace(NewNs.ltrim(':')), - FilePattern(FilePattern), FilePatternRE(FilePattern) { + FilePattern(FilePattern) { + if (auto RegexOrError = llvm::Regex::compile(FilePattern)) { + FilePatternRE = std::move(*RegexOrError); + } FileToReplacements->clear(); llvm::SmallVector OldNsSplitted; llvm::SmallVector NewNsSplitted; Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -152,7 +152,10 @@ RegexText.push_back(C); } RegexText.push_back('$'); - return llvm::Regex(RegexText); + if (auto RegexOrError = llvm::Regex::compile(RegexText)) { + return std::move(*RegexOrError); + } + return llvm::Regex(); } GlobList::GlobList(StringRef Globs) @@ -440,9 +443,13 @@ } llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() { - if (!HeaderFilter) - HeaderFilter.reset( - new llvm::Regex(*Context.getOptions().HeaderFilterRegex)); + if (!HeaderFilter) { + HeaderFilter.reset(new llvm::Regex); + if (auto RegexOrError = + llvm::Regex::compile(*Context.getOptions().HeaderFilterRegex)) { + *HeaderFilter = std::move(*RegexOrError); + } + } return HeaderFilter.get(); } Index: clang-tidy/google/TodoCommentCheck.cpp =================================================================== --- clang-tidy/google/TodoCommentCheck.cpp +++ clang-tidy/google/TodoCommentCheck.cpp @@ -19,8 +19,12 @@ class TodoCommentCheck::TodoCommentHandler : public CommentHandler { public: TodoCommentHandler(TodoCommentCheck &Check, llvm::Optional User) - : Check(Check), User(User ? *User : "unknown"), - TodoMatch("^// *TODO *(\\(.*\\))?:?( )?(.*)$") {} + : Check(Check), User(User ? *User : "unknown") { + if (auto RegexOrError = + llvm::Regex::compile("^// *TODO *(\\(.*\\))?:?( )?(.*)$")) { + TodoMatch = std::move(*RegexOrError); + } + } bool HandleComment(Preprocessor &PP, SourceRange Range) override { StringRef Text = Index: clang-tidy/misc/ArgumentCommentCheck.cpp =================================================================== --- clang-tidy/misc/ArgumentCommentCheck.cpp +++ clang-tidy/misc/ArgumentCommentCheck.cpp @@ -22,8 +22,12 @@ ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - StrictMode(Options.getLocalOrGlobal("StrictMode", 0) != 0), - IdentRE("^(/\\* *)([_A-Za-z][_A-Za-z0-9]*)( *= *\\*/)$") {} + StrictMode(Options.getLocalOrGlobal("StrictMode", 0) != 0) { + if (auto RegexOrError = llvm::Regex::compile( + "^(/\\* *)([_A-Za-z][_A-Za-z0-9]*)( *= *\\*/)$")) { + IdentRE = std::move(*RegexOrError); + } +} void ArgumentCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "StrictMode", StrictMode); Index: clang-tidy/modernize/AvoidBindCheck.cpp =================================================================== --- clang-tidy/modernize/AvoidBindCheck.cpp +++ clang-tidy/modernize/AvoidBindCheck.cpp @@ -47,7 +47,8 @@ static SmallVector buildBindArguments(const MatchFinder::MatchResult &Result, const CallExpr *C) { SmallVector BindArguments; - llvm::Regex MatchPlaceholder("^_([0-9]+)$"); + auto MatchPlaceholder = llvm::ExitOnError("bad regex literal")( + llvm::Regex::compile("^_([0-9]+)$")); // Start at index 1 as first argument to bind is the function name. for (size_t I = 1, ArgCount = C->getNumArgs(); I < ArgCount; ++I) { @@ -63,7 +64,8 @@ *Result.SourceManager, Result.Context->getLangOpts()); SmallVector Matches; - if (B.Kind == BK_Other && MatchPlaceholder.match(B.Tokens, &Matches)) { + if (B.Kind == BK_Other && + MatchPlaceholder.match(B.Tokens, &Matches)) { B.Kind = BK_Placeholder; B.PlaceHolderIndex = std::stoi(Matches[1]); } Index: clang-tidy/readability/IdentifierNamingCheck.cpp =================================================================== --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -230,14 +230,14 @@ static bool matchesStyle(StringRef Name, IdentifierNamingCheck::NamingStyle Style) { - static llvm::Regex Matchers[] = { - llvm::Regex("^.*$"), - llvm::Regex("^[a-z][a-z0-9_]*$"), - llvm::Regex("^[a-z][a-zA-Z0-9]*$"), - llvm::Regex("^[A-Z][A-Z0-9_]*$"), - llvm::Regex("^[A-Z][a-zA-Z0-9]*$"), - llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"), - llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"), + static llvm::Expected Matchers[] = { + llvm::Regex::compile("^.*$"), + llvm::Regex::compile("^[a-z][a-z0-9_]*$"), + llvm::Regex::compile("^[a-z][a-zA-Z0-9]*$"), + llvm::Regex::compile("^[A-Z][A-Z0-9_]*$"), + llvm::Regex::compile("^[A-Z][a-zA-Z0-9]*$"), + llvm::Regex::compile("^[A-Z]([a-z0-9]*(_[A-Z])?)*"), + llvm::Regex::compile("^[a-z]([a-z0-9]*(_[A-Z])?)*"), }; bool Matches = true; @@ -251,7 +251,8 @@ else Matches = false; - if (!Matchers[static_cast(Style.Case)].match(Name)) + auto &M = Matchers[static_cast(Style.Case)]; + if (!(M && M->match(Name))) Matches = false; return Matches; @@ -259,7 +260,7 @@ static std::string fixupWithCase(StringRef Name, IdentifierNamingCheck::CaseType Case) { - static llvm::Regex Splitter( + static auto Splitter = llvm::Regex::compile( "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)"); SmallVector Substrs; @@ -269,7 +270,7 @@ for (auto Substr : Substrs) { while (!Substr.empty()) { SmallVector Groups; - if (!Splitter.match(Substr, &Groups)) + if (!(Splitter && Splitter->match(Substr, &Groups))) break; if (Groups[2].size() > 0) { Index: clang-tidy/readability/NamespaceCommentCheck.cpp =================================================================== --- clang-tidy/readability/NamespaceCommentCheck.cpp +++ clang-tidy/readability/NamespaceCommentCheck.cpp @@ -22,11 +22,15 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" - "namespace( +([a-zA-Z0-9_]+))?\\.? *(\\*/)?$", - llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) { + if (auto RegexOrError = + llvm::Regex::compile("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" + "namespace( +([a-zA-Z0-9_]+))?\\.? *(\\*/)?$", + llvm::Regex::IgnoreCase)) { + NamespaceCommentPattern = std::move(*RegexOrError); + } +} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Index: include-fixer/find-all-symbols/HeaderMapCollector.h =================================================================== --- include-fixer/find-all-symbols/HeaderMapCollector.h +++ include-fixer/find-all-symbols/HeaderMapCollector.h @@ -18,7 +18,7 @@ namespace clang { namespace find_all_symbols { -/// \brief HeaderMappCollector collects all remapping header files. This maps +/// \brief HeaderMapCollector collects all remapping header files. This maps /// complete header names or header name regex patterns to header names. class HeaderMapCollector { public: Index: include-fixer/find-all-symbols/HeaderMapCollector.cpp =================================================================== --- include-fixer/find-all-symbols/HeaderMapCollector.cpp +++ include-fixer/find-all-symbols/HeaderMapCollector.cpp @@ -22,8 +22,11 @@ // regex header mapping. if (RegexHeaderMappingTable) { for (const auto &Entry : *RegexHeaderMappingTable) { - if (llvm::Regex(Entry.first).match(Header)) + // All regexes should come from static string constants. + if (llvm::ExitOnError(Entry.first)(llvm::Regex::compile(Entry.first)) + .match(Header)) { return Entry.second; + } } } return Header; Index: include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp =================================================================== --- include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp +++ include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp @@ -314,10 +314,10 @@ {"include/xlocale.h$", ""}, {"bits/atomic_word.h$", ""}, {"bits/basic_file.h$", ""}, - {"bits/c++allocator.h$", ""}, - {"bits/c++config.h$", ""}, - {"bits/c++io.h$", ""}, - {"bits/c++locale.h$", ""}, + {"bits/c\\+\\+allocator.h$", ""}, + {"bits/c\\+\\+config.h$", ""}, + {"bits/c\\+\\+io.h$", ""}, + {"bits/c\\+\\+locale.h$", ""}, {"bits/cpu_defines.h$", ""}, {"bits/ctype_base.h$", ""}, {"bits/cxxabi_tweaks.h$", ""},