aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/28_regex
diff options
context:
space:
mode:
authorTim Shen <timshen@google.com>2015-01-19 22:56:04 +0000
committerTim Shen <timshen@gcc.gnu.org>2015-01-19 22:56:04 +0000
commit60c176fb459c7780f9cb711e2427e41dca12a54a (patch)
tree2a1f4b55f298c9c15782b158f20da48a36995d76 /libstdc++-v3/testsuite/28_regex
parentb151091dca19708ce7b51fcdf4fffd4b45a831c5 (diff)
downloadgcc-60c176fb459c7780f9cb711e2427e41dca12a54a.zip
gcc-60c176fb459c7780f9cb711e2427e41dca12a54a.tar.gz
gcc-60c176fb459c7780f9cb711e2427e41dca12a54a.tar.bz2
re PR libstdc++/64584 (basic_regex::assign breaks *this if it throws regex_error)
PR libstdc++/64584 PR libstdc++/64585 * include/bits/regex.h (basic_regex<>::basic_regex, basic_regex<>::assign, basic_regex<>::imbue, basic_regex<>::swap, basic_regex<>::mark_count): Drop NFA after imbuing basic_regex; Make assign() transactional against exception. * include/bits/regex_compiler.h (__compile_nfa<>): Add back __compile_nfa SFINAE. * include/std/regex: Adjust include order to avoid __compile_nfa forward declaration. * testsuite/28_regex/basic_regex/assign/char/string.cc: New testcase. * testsuite/28_regex/basic_regex/imbue/string.cc: New testcase. From-SVN: r219865
Diffstat (limited to 'libstdc++-v3/testsuite/28_regex')
-rw-r--r--libstdc++-v3/testsuite/28_regex/basic_regex/assign/char/string.cc20
-rw-r--r--libstdc++-v3/testsuite/28_regex/basic_regex/imbue/string.cc44
2 files changed, 63 insertions, 1 deletions
diff --git a/libstdc++-v3/testsuite/28_regex/basic_regex/assign/char/string.cc b/libstdc++-v3/testsuite/28_regex/basic_regex/assign/char/string.cc
index e0110a1..ee115b5 100644
--- a/libstdc++-v3/testsuite/28_regex/basic_regex/assign/char/string.cc
+++ b/libstdc++-v3/testsuite/28_regex/basic_regex/assign/char/string.cc
@@ -1,4 +1,3 @@
-// { dg-do compile }
// { dg-options "-std=gnu++11" }
// 2007-03-12 Stephen M. Webb <stephen.webb@bregmasoft.com>
@@ -29,6 +28,7 @@
// Tests C++ string assignment of the basic_regex class.
void test01()
{
+ bool test __attribute__((unused)) = true;
typedef std::basic_regex<char> test_type;
std::string s("a*b");
@@ -36,9 +36,27 @@ void test01()
re.assign(s);
}
+// libstdc++/64584
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ std::regex re("", std::regex_constants::extended);
+ auto flags = re.flags();
+ try
+ {
+ re.assign("(", std::regex_constants::icase);
+ VERIFY(false);
+ }
+ catch (const std::regex_error& e)
+ {
+ VERIFY(flags == re.flags());
+ }
+}
+
int
main()
{
test01();
+ test02();
return 0;
}
diff --git a/libstdc++-v3/testsuite/28_regex/basic_regex/imbue/string.cc b/libstdc++-v3/testsuite/28_regex/basic_regex/imbue/string.cc
new file mode 100644
index 0000000..d4d4f47
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/basic_regex/imbue/string.cc
@@ -0,0 +1,44 @@
+// { 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
+// <http://www.gnu.org/licenses/>.
+
+// [28.8.5] class template basic_regex locale
+
+#include <string>
+#include <regex>
+#include <testsuite_hooks.h>
+
+// libstdc++/64585
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ static const char s[] = "a";
+ std::regex re("a");
+ VERIFY(std::regex_search(s, re));
+
+ auto loc = re.imbue(re.getloc());
+ VERIFY(!std::regex_search(s, re));
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}