]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/69794 (std::regex_search match failure with regex object with flags...
authorTim Shen <timshen@google.com>
Wed, 17 Feb 2016 03:33:02 +0000 (03:33 +0000)
committerTim Shen <timshen@gcc.gnu.org>
Wed, 17 Feb 2016 03:33:02 +0000 (03:33 +0000)
2016-02-16  Tim Shen  <timshen@google.com>

PR libstdc++/69794
* include/bits/regex_scanner.h: Add different special character
sets for grep and egrep regex.
* include/bits/regex_scanner.tcc: Use _M_spec_char more uniformly.
* testsuite/28_regex/regression.cc: Add new testcase.

From-SVN: r233482

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/regex_scanner.h
libstdc++-v3/include/bits/regex_scanner.tcc
libstdc++-v3/testsuite/28_regex/regression.cc

index 04dfebf43ac96acb866b957b1eecd8c0c28881a5..be4e95cbb4341a05d78f71e94af090d288609261 100644 (file)
@@ -1,3 +1,11 @@
+2016-02-16  Tim Shen  <timshen@google.com>
+
+       PR libstdc++/69794
+       * include/bits/regex_scanner.h: Add different special character
+       sets for grep and egrep regex.
+       * include/bits/regex_scanner.tcc: Use _M_spec_char more uniformly.
+       * testsuite/28_regex/regression.cc: Add new testcase.
+
 2016-02-08  Jonathan Wakely  <jwakely@redhat.com>
 
        * acinclude.m4 (GLIBCXX_CHECK_MATH11_PROTO): Remove accidentally
index bff73669756c13898904f17595e1c81b9788afd1..37dea840d5be575d25a2d69acd53565f152043bf 100644 (file)
@@ -95,11 +95,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                  : _M_awk_escape_tbl),
     _M_spec_char(_M_is_ecma()
                 ? _M_ecma_spec_char
-                : _M_is_basic()
+                : _M_flags & regex_constants::basic
                 ? _M_basic_spec_char
-                : _M_extended_spec_char),
+                : _M_flags & regex_constants::extended
+                ? _M_extended_spec_char
+                : _M_flags & regex_constants::grep
+                ?  ".[\\*^$\n"
+                : _M_flags & regex_constants::egrep
+                ? ".[\\()*+?{|^$\n"
+                : _M_flags & regex_constants::awk
+                ? _M_extended_spec_char
+                : nullptr),
     _M_at_bracket_start(false)
-    { }
+    { __glibcxx_assert(_M_spec_char); }
 
   protected:
     const char*
@@ -137,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { return _M_flags & regex_constants::awk; }
 
   protected:
+    // TODO: Make them static in the next abi change.
     const std::pair<char, _TokenT> _M_token_tbl[9] =
       {
        {'^', _S_token_line_begin},
index 920cb146407d85f7a05434e6755e3a16b9d28d8b..fedba09a71396f06199b3d81b6c250629d5a3626 100644 (file)
@@ -97,9 +97,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _M_scan_normal()
     {
       auto __c = *_M_current++;
-      const char* __pos;
 
-      if (std::strchr(_M_spec_char, _M_ctype.narrow(__c, '\0')) == nullptr)
+      if (std::strchr(_M_spec_char, _M_ctype.narrow(__c, ' ')) == nullptr)
        {
          _M_token = _S_token_ord_char;
          _M_value.assign(1, __c);
@@ -177,12 +176,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          _M_state = _S_state_in_brace;
          _M_token = _S_token_interval_begin;
        }
-      else if (((__pos = std::strchr(_M_spec_char, _M_ctype.narrow(__c, '\0')))
-                 != nullptr
-               && *__pos != '\0'
-               && __c != ']'
-               && __c != '}')
-              || (_M_is_grep() && __c == '\n'))
+      else if (__c != ']' && __c != '}')
        {
          auto __it = _M_token_tbl;
          auto __narrowc = _M_ctype.narrow(__c, '\0');
index f95bef91760fca92eefa675f11b523e8dd1536e3..c9a3402011ef447e29c6c1ded07bd372e79c98ee 100644 (file)
@@ -33,10 +33,26 @@ test01()
   regex re("((.)", regex_constants::basic);
 }
 
+void
+test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::string re_str
+    {
+      "/abcd" "\n"
+      "/aecf" "\n"
+      "/ghci"
+    };
+  auto rx = std::regex(re_str, std::regex_constants::grep | std::regex_constants::icase);
+  VERIFY(std::regex_search("/abcd", rx));
+}
+
 int
 main()
 {
   test01();
+  test02();
   return 0;
 }