Index: include/llvm/Support/Regex.h =================================================================== --- include/llvm/Support/Regex.h +++ include/llvm/Support/Regex.h @@ -74,7 +74,7 @@ /// 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 @@ -56,7 +56,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. @@ -67,13 +67,8 @@ int rc = llvm_regexec(preg, String.data(), nmatch, pm.data(), REG_STARTEND); - if (rc == REG_NOMATCH) + if (rc == REG_NOMATCH || !rc) return false; - if (rc != 0) { - // regexec can fail due to invalid pattern or running out of memory. - error = rc; - return false; - } // There was a match.