Index: clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h =================================================================== --- clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h +++ clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h @@ -27,7 +27,8 @@ public: MacroUsageCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")), + AllowedRegexpStr(Options.get("AllowedRegexp", "^DEBUG_*")), + AllowedRegexp(AllowedRegexpStr), CheckCapsOnly(Options.get("CheckCapsOnly", false)), IgnoreCommandLineMacros(Options.get("IgnoreCommandLineMacros", true)) {} bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { @@ -41,7 +42,10 @@ private: /// A regular expression that defines how allowed macros must look like. - std::string AllowedRegexp; + /// Store compiled and original to allow serialisation. + std::string AllowedRegexpStr; + llvm::Regex AllowedRegexp; + /// Control if only the check shall only test on CAPS_ONLY macros. bool CheckCapsOnly; /// Should the macros without a valid location be diagnosed? Index: clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp +++ clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp @@ -32,7 +32,7 @@ class MacroUsageCallbacks : public PPCallbacks { public: MacroUsageCallbacks(MacroUsageCheck *Check, const SourceManager &SM, - StringRef RegExp, bool CapsOnly, bool IgnoreCommandLine) + const llvm::Regex &RegExp, bool CapsOnly, bool IgnoreCommandLine) : Check(Check), SM(SM), RegExp(RegExp), CheckCapsOnly(CapsOnly), IgnoreCommandLineMacros(IgnoreCommandLine) {} void MacroDefined(const Token &MacroNameTok, @@ -47,7 +47,7 @@ return; StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName(); - if (!CheckCapsOnly && !llvm::Regex(RegExp).match(MacroName)) + if (!CheckCapsOnly && !RegExp.match(MacroName)) Check->warnMacro(MD, MacroName); if (CheckCapsOnly && !isCapsOnly(MacroName)) @@ -57,14 +57,14 @@ private: MacroUsageCheck *Check; const SourceManager &SM; - StringRef RegExp; + const llvm::Regex &RegExp; bool CheckCapsOnly; bool IgnoreCommandLineMacros; }; } // namespace void MacroUsageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "AllowedRegexp", AllowedRegexp); + Options.store(Opts, "AllowedRegexp", AllowedRegexpStr); Options.store(Opts, "CheckCapsOnly", CheckCapsOnly); Options.store(Opts, "IgnoreCommandLineMacros", IgnoreCommandLineMacros); }