Re: [Patch, libstdc++/68863] Let lookahead regex use captured contents

2015-12-14 Thread Jonathan Wakely

On 11/12/15 22:11 -0800, Tim Shen wrote:

This is a one-line quick fix for correctness.

I bootstrapped trunk and tested on x86_64-pc-linux-gnu, but I wish I
can backport it at least to gcc-5-branch.


I don't fully understand the patch, but it's OK for trunk, and if
you're confident it's definitely correct and safe it's OK for the
gcc-5 and gcc-4_9 branches too.

Was it just completely wrong before, creating a vector of
default-constructed match results, that were not matched?



Re: [Patch, libstdc++/68863] Let lookahead regex use captured contents

2015-12-14 Thread Tim Shen
On Mon, Dec 14, 2015 at 10:03 AM, Jonathan Wakely  wrote:
> OK then I do understand it and it's definitely OK to commit :-)
>
> Thanks.
>

Committed to trunk, gcc 5 and gcc 4.9.


-- 
Regards,
Tim Shen


Re: [Patch, libstdc++/68863] Let lookahead regex use captured contents

2015-12-14 Thread Tim Shen
On Mon, Dec 14, 2015 at 3:00 AM, Jonathan Wakely  wrote:
> I don't fully understand the patch, but it's OK for trunk, and if
> you're confident it's definitely correct and safe it's OK for the
> gcc-5 and gcc-4_9 branches too.
>
> Was it just completely wrong before, creating a vector of
> default-constructed match results, that were not matched?
>

Yes, that's the case. I'm not sure why I missed this. Perhaps all I
was focusing on is to get the captures in the lookahead sub-expression
out of it, so later user can use it; but I didn't think about the
other way around.

-- 
Regards,
Tim Shen


Re: [Patch, libstdc++/68863] Let lookahead regex use captured contents

2015-12-14 Thread Jonathan Wakely

On 14/12/15 09:58 -0800, Tim Shen wrote:

On Mon, Dec 14, 2015 at 3:00 AM, Jonathan Wakely  wrote:

I don't fully understand the patch, but it's OK for trunk, and if
you're confident it's definitely correct and safe it's OK for the
gcc-5 and gcc-4_9 branches too.

Was it just completely wrong before, creating a vector of
default-constructed match results, that were not matched?



Yes, that's the case. I'm not sure why I missed this. Perhaps all I
was focusing on is to get the captures in the lookahead sub-expression
out of it, so later user can use it; but I didn't think about the
other way around.


OK then I do understand it and it's definitely OK to commit :-)

Thanks.



Re: [Patch, libstdc++/68863] Let lookahead regex use captured contents

2015-12-11 Thread Tim Shen
On Fri, Dec 11, 2015 at 10:08 PM, Tim Shen  wrote:
> This is a one-line quick fix for correctness.
>
> I bootstrapped trunk and tested on x86_64-pc-linux-gnu, but I wish I
> can backport it at least to gcc-5-branch.
>

Sorry, I didn't actually write the changelog :P. Updated.


-- 
Regards,
Tim Shen
commit d4bd253408c31f71adb2df6641df0f4d798855c9
Author: Tim Shen 
Date:   Fri Dec 11 21:34:38 2015 -0800

2015-12-12  Tim Shen  

PR libstdc++/68863
* include/bits/regex_executor.tcc (_Executor::_M_lookahead):
Copy the captured content for lookahead, so that the backreferences
inside can refer to them.
* testsuite/28_regex/algorithms/regex_match/ecma/char/68863.cc:
New testcase.

diff --git a/libstdc++-v3/include/bits/regex_executor.tcc 
b/libstdc++-v3/include/bits/regex_executor.tcc
index a13f0d5..f5be4d7 100644
--- a/libstdc++-v3/include/bits/regex_executor.tcc
+++ b/libstdc++-v3/include/bits/regex_executor.tcc
@@ -147,7 +147,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 bool _Executor<_BiIter, _Alloc, _TraitsT, __dfs_mode>::
 _M_lookahead(_StateIdT __next)
 {
-  _ResultsVec __what(_M_cur_results.size());
+  // Backreferences may refer to captured content.
+  // We may want to make this faster by not copying,
+  // but let's not be clever prematurely.
+  _ResultsVec __what(_M_cur_results);
   _Executor __sub(_M_current, _M_end, __what, _M_re, _M_flags);
   __sub._M_states._M_start = __next;
   if (__sub._M_search_from_first())
diff --git 
a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/68863.cc 
b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/68863.cc
new file mode 100644
index 000..9e7a9a7
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/68863.cc
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2015 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// 28.11.2 regex_match
+
+#include 
+#include 
+#include 
+
+using namespace __gnu_test;
+using namespace std;
+
+// libstdc++/68863
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  VERIFY(!std::regex_match("aa", std::regex("(.)(?!\\1).")));
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}