[PATCH] [libcxx] Fix match_results for alternatives

Agustín Bergé kaballo86 at hotmail.com
Wed Jan 21 15:47:53 PST 2015


Hi mclow.lists, EricWF,

Initialize submatch results to unmatched. They will not be modified for failed alternatives (they might not even be looked at), and would otherwise leave the pair of iterators value-initialized instead of pointing to the end of the searched sequence. Fixes PR22061.

http://reviews.llvm.org/D7111

Files:
  include/regex
  test/std/re/re.results/re.results.acc/index.pass.cpp

Index: include/regex
===================================================================
--- include/regex
+++ include/regex
@@ -5601,12 +5601,17 @@
     __node* __st = __start_.get();
     if (__st)
     {
+        sub_match<const _CharT*> __unmatched;
+        __unmatched.first   = __last;
+        __unmatched.second  = __last;
+        __unmatched.matched = false;
+
         __states.push_back(__state());
         __states.back().__do_ = 0;
         __states.back().__first_ = __first;
         __states.back().__current_ = __first;
         __states.back().__last_ = __last;
-        __states.back().__sub_matches_.resize(mark_count());
+        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
         __states.back().__loop_data_.resize(__loop_count());
         __states.back().__node_ = __st;
         __states.back().__flags_ = __flags;
@@ -5746,12 +5751,17 @@
     __node* __st = __start_.get();
     if (__st)
     {
+        sub_match<const _CharT*> __unmatched;
+        __unmatched.first   = __last;
+        __unmatched.second  = __last;
+        __unmatched.matched = false;
+
         __states.push_back(__state());
         __states.back().__do_ = 0;
         __states.back().__first_ = __first;
         __states.back().__current_ = __first;
         __states.back().__last_ = __last;
-        __states.back().__sub_matches_.resize(mark_count());
+        __states.back().__sub_matches_.resize(mark_count(), __unmatched);
         __states.back().__loop_data_.resize(__loop_count());
         __states.back().__node_ = __st;
         __states.back().__flags_ = __flags;
Index: test/std/re/re.results/re.results.acc/index.pass.cpp
===================================================================
--- test/std/re/re.results/re.results.acc/index.pass.cpp
+++ test/std/re/re.results/re.results.acc/index.pass.cpp
@@ -21,7 +21,7 @@
 {
     std::match_results<const char*> m;
     const char s[] = "abcdefghijk";
-    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi|(z)")));
 
     assert(m[0].first == s+2);
     assert(m[0].second == s+9);
@@ -42,6 +42,10 @@
     assert(m[4].first == s+11);
     assert(m[4].second == s+11);
     assert(m[4].matched == false);
+
+    assert(m[5].first == s+11);
+    assert(m[5].second == s+11);
+    assert(m[4].matched == false);
 }
 
 int main()

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7111.18563.patch
Type: text/x-patch
Size: 2396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150121/40e0fe5b/attachment.bin>


More information about the cfe-commits mailing list