diff mbox

Fix a bug of consecutive range quantifiers in regex

Message ID CAPrifD=SW2VYS57PO2uJ679TcDKCAN4-GWC7nVp8qRNGuYzDiw@mail.gmail.com
State New
Headers show

Commit Message

Tim Shen April 24, 2014, 3:49 p.m. UTC
On Thu, Apr 24, 2014 at 6:56 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> Unless I'm doing something wrong the new tests you added already give
> the right results, do you have a testcase that fails with the current
> code?

This testcase fails before the patch. Sorry for that.

Comments

Jonathan Wakely April 24, 2014, 4:38 p.m. UTC | #1
On 24/04/14 11:49 -0400, Tim Shen wrote:
>This testcase fails before the patch. Sorry for that.

Great, thanks - OK for trunk.

Assuming no problems on the trunk we might want to backport it for
4.9.1 in a few weeks.
Tim Shen April 24, 2014, 6:29 p.m. UTC | #2
On Thu, Apr 24, 2014 at 12:38 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
> Great, thanks - OK for trunk.
>
> Assuming no problems on the trunk we might want to backport it for
> 4.9.1 in a few weeks.
>

Committed. Thanks.
diff mbox

Patch

diff --git a/libstdc++-v3/include/bits/regex_automaton.tcc b/libstdc++-v3/include/bits/regex_automaton.tcc
index 759b053..1476ae2 100644
--- a/libstdc++-v3/include/bits/regex_automaton.tcc
+++ b/libstdc++-v3/include/bits/regex_automaton.tcc
@@ -197,20 +197,18 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  // _M_insert_state() never return -1
 	  auto __id = _M_nfa._M_insert_state(__dup);
 	  __m[__u] = __id;
-	  if (__u == _M_end)
-	    continue;
-	  if (__dup._M_next != _S_invalid_state_id && __m[__dup._M_next] == -1)
-	    __stack.push(__dup._M_next);
 	  if (__dup._M_opcode == _S_opcode_alternative
 	      || __dup._M_opcode == _S_opcode_subexpr_lookahead)
 	    if (__dup._M_alt != _S_invalid_state_id && __m[__dup._M_alt] == -1)
 	      __stack.push(__dup._M_alt);
+	  if (__u == _M_end)
+	    continue;
+	  if (__dup._M_next != _S_invalid_state_id && __m[__dup._M_next] == -1)
+	    __stack.push(__dup._M_next);
 	}
-      long __size = static_cast<long>(__m.size());
-      for (long __k = 0; __k < __size; __k++)
+      for (auto __v : __m)
 	{
-	  long __v;
-	  if ((__v = __m[__k]) == -1)
+	  if (__v == -1)
 	    continue;
 	  auto& __ref = _M_nfa[__v];
 	  if (__ref._M_next != _S_invalid_state_id)
diff --git a/libstdc++-v3/testsuite/28_regex/basic_regex/multiple_quantifiers.cc b/libstdc++-v3/testsuite/28_regex/basic_regex/multiple_quantifiers.cc
index 5670cbb..8243eea 100644
--- a/libstdc++-v3/testsuite/28_regex/basic_regex/multiple_quantifiers.cc
+++ b/libstdc++-v3/testsuite/28_regex/basic_regex/multiple_quantifiers.cc
@@ -21,7 +21,10 @@ 
 // Tests multiple consecutive quantifiers
 
 #include <regex>
+#include <testsuite_hooks.h>
+#include <testsuite_regex.h>
 
+using namespace __gnu_test;
 using namespace std;
 
 int
@@ -29,5 +32,6 @@  main()
 {
   regex re1("a++");
   regex re2("(a+)+");
+  VERIFY(regex_match_debug("aa", regex("(a)*{3}")));
   return 0;
 }