Index: include/llvm/Support/Regex.h =================================================================== --- include/llvm/Support/Regex.h +++ include/llvm/Support/Regex.h @@ -75,7 +75,8 @@ /// the first group is always the entire pattern. /// /// This returns true on a successful match. - bool match(StringRef String, SmallVectorImpl *Matches = nullptr); + bool match(StringRef String, + SmallVectorImpl *Matches = nullptr) const; /// sub - Return the result of replacing the first match of the regex in /// \p String with the \p Repl string. Backreferences like "\0" in the Index: lib/Support/Regex.cpp =================================================================== --- lib/Support/Regex.cpp +++ lib/Support/Regex.cpp @@ -58,7 +58,7 @@ return preg->re_nsub; } -bool Regex::match(StringRef String, SmallVectorImpl *Matches){ +bool Regex::match(StringRef String, SmallVectorImpl *Matches) const { unsigned nmatch = Matches ? preg->re_nsub+1 : 0; // pmatch needs to have at least one element. @@ -68,14 +68,8 @@ pm[0].rm_eo = String.size(); int rc = llvm_regexec(preg, String.data(), nmatch, pm.data(), REG_STARTEND); - - if (rc == REG_NOMATCH) - return false; - if (rc != 0) { - // regexec can fail due to invalid pattern or running out of memory. - error = rc; + if (rc != 0) return false; - } // There was a match.