[PATCH] Fix non-portable std::regex test and test more cases

Jonathan Wakely jwakely@redhat.com
Sun Jul 31 18:46:00 GMT 2016


This test uses \n inside a raw string literal, which is not a newline
but just a backslash followed by 'n', and that's not a valid POSIX BRE
so the test fails when run with -std=c++11 rather than -std=gnu++11.

I've replaced \n with newlines, and also tested the "expected fail"
string, which works fine since GCC 4.9 got full <regex> support.

	* testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc: Fix
	test to not rely on GNU extension (escaped normal characters in POSIX
	BRE). Enable tests for other strings which are now supported.

Tested x86_64-linux, committed to trunk.


-------------- next part --------------
commit f98dbae4796cb4164c0f6f07aea208165a806615
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sun Jul 31 19:35:49 2016 +0100

    Fix non-portable std::regex test and test more cases
    
    	* testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc: Fix
    	test to not rely on GNU extension (escaped normal characters in POSIX
    	BRE). Enable tests for other strings which are now supported.

diff --git a/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc b/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc
index 5625653..758f216 100644
--- a/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc
+++ b/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc
@@ -1,4 +1,3 @@
-// { dg-options "-std=gnu++11" }
 
 // 2012-08-20  Benjamin Kosnik <bkoz@redhat.com>
 //
@@ -31,17 +30,27 @@ test01()
 
   // raw string literals
 
-  //string_type sre0(R"(\d{3}-\d{3}-\d{4})"); // expected fail
+  string_type sre0(R"(\d{3}-\d{3}-\d{4})");
 
-  string_type sre1(R"( this\n  and new : forms\n  )");
+  string_type sre1(R"( this
+  and new : forms
+  )");
 
   string_type sre2(R"([:num:]{3}-[:num:]{3}-[:num:]{4})");
 
   // 1
-  regex_type re(R"( this\n  and new : forms\n  )", std::regex::basic);
+  regex_type re0(R"(\d{3}-\d{3}-\d{4})", std::regex::ECMAScript);
+
+  regex_type re1(R"( this
+  and new : forms
+  )", std::regex::basic);
+
+  regex_type re2(R"([:num:]{3}-[:num:]{3}-[:num:]{4})", std::regex::basic);
 
   // 2
+  regex_sanity_check(sre0, std::regex::ECMAScript);
   regex_sanity_check(sre1);
+  regex_sanity_check(sre2);
 }
 
 int main()


More information about the Gcc-patches mailing list