public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Let ordinary escaping in POSIX regex be valid
@ 2013-09-27  8:15 Tim Shen
  2013-09-27 11:17 ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Tim Shen @ 2013-09-27  8:15 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 376 bytes --]

POSIX ERE says that escaping an ordinary char, say R"\n" is not
permitted, because 'n' is not a special char. However, they also say
that : "Implementations are permitted to extend the language to allow
these. Conforming applications cannot use such constructs."

So let's support it not to make users surprised.

Booted and tested under -m32 and -m64

Thanks!


-- 
Tim Shen

[-- Attachment #2: a.patch --]
[-- Type: application/octet-stream, Size: 1349 bytes --]

commit b61a06c29cabfe6ba4ad171965adc3bbb76c4cd8
Author: tim <timshen91@gmail.com>
Date:   Thu Sep 26 19:25:18 2013 -0400

    2013-09-27  Tim Shen <timshen91@gmail.com>
    
    	* include/bits/regex_scanner.tcc (_Scanner<>::_M_eat_escape_posix):
    	Let ordinary char escaping in POSIX be valid.
    	* testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc: Test this
    	change.

diff --git a/libstdc++-v3/include/bits/regex_scanner.tcc b/libstdc++-v3/include/bits/regex_scanner.tcc
index e0dff90..f9f77de 100644
--- a/libstdc++-v3/include/bits/regex_scanner.tcc
+++ b/libstdc++-v3/include/bits/regex_scanner.tcc
@@ -457,7 +457,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  _M_value.assign(1, __c);
 	}
       else
-	__throw_regex_error(regex_constants::error_escape);
+	{
+	  _M_token = _S_token_ord_char;
+	  _M_value.assign(1, __c);
+	}
       ++_M_current;
     }
 
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 68fd56a..624b80c 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,5 +1,4 @@
 // { dg-options "-std=c++0x" }
-// { dg-do run { xfail *-*-* } }
 
 // 2012-08-20  Benjamin Kosnik <bkoz@redhat.com>
 //

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Patch] Let ordinary escaping in POSIX regex be valid
  2013-09-27  8:15 [Patch] Let ordinary escaping in POSIX regex be valid Tim Shen
@ 2013-09-27 11:17 ` Jonathan Wakely
  2013-09-27 14:08   ` Paolo Carlini
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2013-09-27 11:17 UTC (permalink / raw)
  To: Tim Shen; +Cc: libstdc++, gcc-patches

On 27 September 2013 03:15, Tim Shen wrote:
> POSIX ERE says that escaping an ordinary char, say R"\n" is not
> permitted, because 'n' is not a special char. However, they also say
> that : "Implementations are permitted to extend the language to allow
> these. Conforming applications cannot use such constructs."
>
> So let's support it not to make users surprised.
>
> Booted and tested under -m32 and -m64

I'm wondering whether we want to have a stricter mode that doesn't
allow them, to help users avoid creating non-portable programs.  We
could check the value of the preprocessor macro __STRICT_ANSI__, which
is set by -std=c++11 but not by -std=gnu++11, although that's not
really the right flag. We want something more like the GNU shell
utils' POSIXLY_CORRECT.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Patch] Let ordinary escaping in POSIX regex be valid
  2013-09-27 11:17 ` Jonathan Wakely
@ 2013-09-27 14:08   ` Paolo Carlini
  2013-09-27 14:15     ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Carlini @ 2013-09-27 14:08 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Tim Shen, libstdc++, gcc-patches

On 9/27/13 4:34 AM, Jonathan Wakely wrote:
> On 27 September 2013 03:15, Tim Shen wrote:
>> POSIX ERE says that escaping an ordinary char, say R"\n" is not
>> permitted, because 'n' is not a special char. However, they also say
>> that : "Implementations are permitted to extend the language to allow
>> these. Conforming applications cannot use such constructs."
>>
>> So let's support it not to make users surprised.
>>
>> Booted and tested under -m32 and -m64
> I'm wondering whether we want to have a stricter mode that doesn't
> allow them, to help users avoid creating non-portable programs.  We
> could check the value of the preprocessor macro __STRICT_ANSI__, which
> is set by -std=c++11 but not by -std=gnu++11, although that's not
> really the right flag. We want something more like the GNU shell
> utils' POSIXLY_CORRECT.
Indeed. I think that for now __STRICT_ANSI__ can do, it's important to 
manage to accept those otherwise, as we discovered yesterday, we easily 
reject quite a few rather sensible regex users can write or find in 
examples: this started when Tim, upon my suggestion, tried the examples 
in the new edition of Nicolai Josuttis book and found in one those an 
escaped closed curly bracket (note, closed, open are definitely fine), 
which apparently most of the other implementations do not reject.

Paolo.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Patch] Let ordinary escaping in POSIX regex be valid
  2013-09-27 14:08   ` Paolo Carlini
@ 2013-09-27 14:15     ` Jonathan Wakely
  2013-09-27 20:30       ` Tim Shen
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2013-09-27 14:15 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: Tim Shen, libstdc++, gcc-patches

On 27 September 2013 13:32, Paolo Carlini wrote:
> On 9/27/13 4:34 AM, Jonathan Wakely wrote:
>>
>> On 27 September 2013 03:15, Tim Shen wrote:
>>>
>>> POSIX ERE says that escaping an ordinary char, say R"\n" is not
>>> permitted, because 'n' is not a special char. However, they also say
>>> that : "Implementations are permitted to extend the language to allow
>>> these. Conforming applications cannot use such constructs."
>>>
>>> So let's support it not to make users surprised.
>>>
>>> Booted and tested under -m32 and -m64
>>
>> I'm wondering whether we want to have a stricter mode that doesn't
>> allow them, to help users avoid creating non-portable programs.  We
>> could check the value of the preprocessor macro __STRICT_ANSI__, which
>> is set by -std=c++11 but not by -std=gnu++11, although that's not
>> really the right flag. We want something more like the GNU shell
>> utils' POSIXLY_CORRECT.
>
> Indeed. I think that for now __STRICT_ANSI__ can do, it's important to
> manage to accept those otherwise, as we discovered yesterday, we easily
> reject quite a few rather sensible regex users can write or find in
> examples: this started when Tim, upon my suggestion, tried the examples in
> the new edition of Nicolai Josuttis book and found in one those an escaped
> closed curly bracket (note, closed, open are definitely fine), which
> apparently most of the other implementations do not reject.

Ah I see.  I definitely agree it's good to accept that instead of
being unnecessarily strict, but other people will want the option of
strict conformance, so I think we can please everyone with something
like:

else
  {
#ifdef __STRICT_ANSI__
    __throw_regex_error(regex_constants::error_escape);
#else
   _M_token = _S_token_ord_char;
   _M_value.assign(1, __c);
#endif
  }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Patch] Let ordinary escaping in POSIX regex be valid
  2013-09-27 14:15     ` Jonathan Wakely
@ 2013-09-27 20:30       ` Tim Shen
  2013-09-27 22:13         ` Paolo Carlini
  0 siblings, 1 reply; 7+ messages in thread
From: Tim Shen @ 2013-09-27 20:30 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Paolo Carlini, libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

On Fri, Sep 27, 2013 at 9:37 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> Ah I see.  I definitely agree it's good to accept that instead of
> being unnecessarily strict, but other people will want the option of
> strict conformance, so I think we can please everyone with something
> like:
>
> else
>   {
> #ifdef __STRICT_ANSI__
>     __throw_regex_error(regex_constants::error_escape);
> #else
>    _M_token = _S_token_ord_char;
>    _M_value.assign(1, __c);
> #endif
>   }

Sorry for late >.<

Do I need to bootstrap again?


-- 
Tim Shen

[-- Attachment #2: a.patch --]
[-- Type: application/octet-stream, Size: 1478 bytes --]

commit 0b2d28bcbffa4c4839c9fe4f00c6460a38c5eeae
Author: tim <timshen91@gmail.com>
Date:   Thu Sep 26 19:25:18 2013 -0400

    2013-09-27  Tim Shen <timshen91@gmail.com>
    
    	* include/bits/regex_scanner.tcc (_Scanner<>::_M_eat_escape_posix):
    	Let ordinary char escaping in POSIX be valid.
    	* testsuite/28_regex/basic_regex/ctors/basic/raw_string.cc: Test this
    	change.

diff --git a/libstdc++-v3/include/bits/regex_scanner.tcc b/libstdc++-v3/include/bits/regex_scanner.tcc
index e0dff90..fc82738 100644
--- a/libstdc++-v3/include/bits/regex_scanner.tcc
+++ b/libstdc++-v3/include/bits/regex_scanner.tcc
@@ -457,7 +457,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  _M_value.assign(1, __c);
 	}
       else
-	__throw_regex_error(regex_constants::error_escape);
+	{
+#ifdef __STRICT_ANSI__
+	  __throw_regex_error(regex_constants::error_escape);
+#else
+	  _M_token = _S_token_ord_char;
+	  _M_value.assign(1, __c);
+#endif
+	}
       ++_M_current;
     }
 
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 68fd56a..d005dc0 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,5 +1,4 @@
-// { dg-options "-std=c++0x" }
-// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++11" }
 
 // 2012-08-20  Benjamin Kosnik <bkoz@redhat.com>
 //

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Patch] Let ordinary escaping in POSIX regex be valid
  2013-09-27 20:30       ` Tim Shen
@ 2013-09-27 22:13         ` Paolo Carlini
  2013-09-28 16:34           ` Tim Shen
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Carlini @ 2013-09-27 22:13 UTC (permalink / raw)
  To: Tim Shen, Jonathan Wakely; +Cc: libstdc++, gcc-patches



Hi

Tim Shen <timshen91@gmail.com> ha scritto:
>Do I need to bootstrap again?

Nah, only double check that the testcase you are un-xfail-ing uses -std=gnu++11, otherwise will not pass ;)

Paolo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Patch] Let ordinary escaping in POSIX regex be valid
  2013-09-27 22:13         ` Paolo Carlini
@ 2013-09-28 16:34           ` Tim Shen
  0 siblings, 0 replies; 7+ messages in thread
From: Tim Shen @ 2013-09-28 16:34 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: Jonathan Wakely, libstdc++, gcc-patches

On Fri, Sep 27, 2013 at 4:30 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Nah, only double check that the testcase you are un-xfail-ing uses -std=gnu++11, otherwise will not pass ;)

Committed :)

Thanks!


-- 
Tim Shen

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-09-28 13:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-27  8:15 [Patch] Let ordinary escaping in POSIX regex be valid Tim Shen
2013-09-27 11:17 ` Jonathan Wakely
2013-09-27 14:08   ` Paolo Carlini
2013-09-27 14:15     ` Jonathan Wakely
2013-09-27 20:30       ` Tim Shen
2013-09-27 22:13         ` Paolo Carlini
2013-09-28 16:34           ` Tim Shen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).