From 9e6b3783d13f5136c727e6a8247ce2398edc0bb5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 3 Jul 2017 23:52:06 +0300 Subject: Implement workaround for libc++ bug (#33681) in regex_replace_ex() --- libbutl/regex.txx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'libbutl/regex.txx') diff --git a/libbutl/regex.txx b/libbutl/regex.txx index 9c6342b..52bddfd 100644 --- a/libbutl/regex.txx +++ b/libbutl/regex.txx @@ -3,7 +3,7 @@ // license : MIT; see accompanying LICENSE file #include -#include // size_t +#include // size_t, _LIBCPP_VERSION namespace butl { @@ -34,10 +34,26 @@ namespace butl regex_it e; bool match (b != e); + // For libc++, the end-of-sequence regex iterator can never be reached + // for some regular expressions (LLVM bug #33681). We will check if the + // matching sequence start is the same as the one for the previous match + // and bail out if that's the case. + // +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 4000 + str_it pm; +#endif + for (regex_it i (b); i != e; ++i) { const match_results& m (*i); +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 4000 + if (i != b && m[0].first == pm) + break; + + pm = m[0].first; +#endif + // Copy the preceeding unmatched substring, save the beginning of the // one that follows. // -- cgit v1.1