aboutsummaryrefslogtreecommitdiff
path: root/libbutl/regex.txx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-07-03 23:52:06 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-07-03 23:52:06 +0300
commit9e6b3783d13f5136c727e6a8247ce2398edc0bb5 (patch)
treeccc770c622f9534dd4f6604928643a593de9b942 /libbutl/regex.txx
parent4dabcf0062bc4bdfa807f7b8952eac649c9d65b5 (diff)
Implement workaround for libc++ bug (#33681) in regex_replace_ex()
Diffstat (limited to 'libbutl/regex.txx')
-rw-r--r--libbutl/regex.txx18
1 files changed, 17 insertions, 1 deletions
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 <locale>
-#include <cstddef> // size_t
+#include <cstddef> // 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<str_it>& 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.
//