]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/64680 (basic_regex::operator= does not reset flags)
authorTim Shen <timshen@google.com>
Tue, 3 Feb 2015 09:01:36 +0000 (09:01 +0000)
committerTim Shen <timshen@gcc.gnu.org>
Tue, 3 Feb 2015 09:01:36 +0000 (09:01 +0000)
PR libstdc++/64680
Backported from mainline
2015-01-22  Tim Shen  <timshen@google.com>

* include/bits/regex.h (basic_regex<>::basic_regex,
basic_regex<>::operator=, basic_regex<>::imbue): Conform to the
standard interface.
* testsuite/28_regex/basic_regex/assign/char/cstring.cc: New testcase.

From-SVN: r220366

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/regex.h
libstdc++-v3/testsuite/28_regex/basic_regex/assign/char/cstring.cc

index ba81f03633ca8e9c9488738f4b3983926e61bc0e..3c8b9e8126303cc268ae3fae535f5f67483804bf 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-03  Tim Shen  <timshen@google.com>
+
+       PR libstdc++/64680
+       Backported from mainline
+       2015-01-22  Tim Shen  <timshen@google.com>
+
+       * include/bits/regex.h (basic_regex<>::basic_regex,
+       basic_regex<>::operator=, basic_regex<>::imbue): Conform to the
+       standard interface.
+       * testsuite/28_regex/basic_regex/assign/char/cstring.cc: New testcase.
+
 2015-02-03  Tim Shen  <timshen@google.com>
 
        PR libstdc++/64649
index b358c79ee3e5a009822317e753a0048ff8ecc416..ea706799ed66c26add8da531a5ffa80e12163fcc 100644 (file)
@@ -449,7 +449,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        */
       explicit
       basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
-      : basic_regex(__p, __p + _Rx_traits::length(__p), __f)
+      : basic_regex(__p, __p + char_traits<_Ch_type>::length(__p), __f)
       { }
 
       /**
@@ -584,7 +584,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        */
       basic_regex&
       operator=(const _Ch_type* __p)
-      { return this->assign(__p, flags()); }
+      { return this->assign(__p); }
+
+      /**
+       * @brief Replaces a regular expression with a new one constructed from
+       * an initializer list.
+       *
+       * @param __l  The initializer list.
+       *
+       * @throws regex_error if @p __l is not a valid regular expression.
+       */
+      basic_regex&
+      operator=(initializer_list<_Ch_type> __l)
+      { return this->assign(__l.begin(), __l.end()); }
 
       /**
        * @brief Replaces a regular expression with a new one constructed from
@@ -595,7 +607,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _Ch_typeraits, typename _Alloc>
        basic_regex&
        operator=(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s)
-       { return this->assign(__s, flags()); }
+       { return this->assign(__s); }
 
       // [7.8.3] assign
       /**
@@ -753,7 +765,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       locale_type
       imbue(locale_type __loc)
       {
-       _M_automaton = nullptr;
+       _M_automaton.reset();
        return _M_traits.imbue(__loc);
       }
 
index 16dae9a16a642d2e76e2fae62692e865622f4a80..7011d1c852985e31d6f2c2c239fb28aef1830ec2 100644 (file)
@@ -1,5 +1,4 @@
-// { dg-do compile }
-// { dg-options "-std=c++0x" }
+// { dg-options "-std=c++11" }
 
 // 2009-06-05  Stephen M. Webb  <stephen.webb@bregmasoft.ca>
 //
@@ -36,9 +35,19 @@ void test01()
   re.assign(cs);
 }
 
+// basic_regex::operator=() resets flags. libstdc++/64680
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::regex re("[[:alnum:]]", std::regex_constants::basic);
+  re = "\\w+";
+}
+
 int
 main()
 { 
   test01();
+  test02();
   return 0;
 }