[libstdc++/61227] Support regex like "[\w]"

Jonathan Wakely jwakely@redhat.com
Mon May 19 20:41:00 GMT 2014

On 19/05/14 11:08 -0400, Tim Shen wrote:
>    	* testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc:
>    	New testcase.

This sounds like it's adding a new file, not extending it with new

>       std::vector<_CharT>                       _M_char_set;
>       std::vector<_StringT>                     _M_equiv_set;
>       std::vector<pair<_StrTransT, _StrTransT>> _M_range_set;
>+      std::vector<_CharClassT>                  _M_neg_class_set;

It's unfortunate we need another whole std::vector to handle this, but
if it fixes the bug it's OK.

>       _CharClassT                               _M_class_set;
>       _TransT                                   _M_translator;
>       const _TraitsT&                           _M_traits;
>     _M_apply(_CharT __ch, false_type) const
>     {
>       bool __ret = false;
>+      // TODO Refactor this piece of junk.
>       if (std::find(_M_char_set.begin(), _M_char_set.end(),
> 		    _M_translator._M_translate(__ch))
> 	  != _M_char_set.end())

I'm going to check in my factoring patches soon, so there's no need to
add this comment.

>diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/61227.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/61227.cc
>new file mode 100644
>index 0000000..2d854f6
>--- /dev/null
>+++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/61227.cc
>@@ -0,0 +1,47 @@
>+// { dg-options "-std=gnu++11" }
>+// Copyright (C) 2014 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
>+// 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
>+// <http://www.gnu.org/licenses/>.
>+// 28.11.2 regex_match
>+#include <regex>
>+#include <testsuite_hooks.h>
>+#include <testsuite_regex.h>
>+using namespace __gnu_test;
>+using namespace std;
>+// libstdc++/61227
>+  std::regex r1{R"([^\w ])"};
>+  std::regex r2{R"(\b\w+\b)"};
>+  std::regex r3{R"(\b\w+\b)"};
>+  std::regex r4{"//.*$"};
>+  std::regex r5{R"((?:[^;"]|"[^"]*")+)"};
>+  std::regex r6{R"~~(([^\s"]+)|"([^"]*)")~~"};

This test case from the PR is not very useful, because only r1 and r6
trigger the bug, the other ones are just noise and make it harder to
interpret what is being tested.

As you've added tests for \d, \s, \w and their negative forms to
quoted_char.cc I don't think we need this new file.

The patch is OK with the ChangeLog tweak and omitting the new file.

Thanks for the quick fix.

More information about the Libstdc++ mailing list