Message ID | CAPrifD=s5czQ3pHGFLjybk1rK7Ebp3LboDtZ9nDoaXqScN_g2g@mail.gmail.com |
---|---|
State | New |
Headers | show |
On 20/01/14 17:43 -0500, Tim Shen wrote: >The semantic of `nosubs` should simply be that `let all parentheses >not be a subexpression and do not capture it`. It's not clear to me whether the standard says that nosubs implies mark_count() == 0 or that the mark count remains the same, but no sub-expression matches are stored in the results. What does Boost.Regex do?
On Tue, Jan 21, 2014 at 5:08 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> What does Boost.Regex do?
My conclusion is actually based on Boost.Regex's behavior.
boost::basic_regex::mark_count() returns 1 with nosubs flag. Note that
boost::basic_regex::mark_count() == std::basic_regex::mark_count() +
1, because std does not count the 0th capture (the whole regex) in.
libc++'s mark_count returns 0 as well.
On 21/01/14 14:14 -0500, Tim Shen wrote: >My conclusion is actually based on Boost.Regex's behavior. >boost::basic_regex::mark_count() returns 1 with nosubs flag. Note that >boost::basic_regex::mark_count() == std::basic_regex::mark_count() + >1, because std does not count the 0th capture (the whole regex) in. >libc++'s mark_count returns 0 as well. OK, thanks for confirming that. In that case your patch is OK to commit. I'll raise a defect report against the standard as I don't think the specification of nosubs is clear. If that's what it means then it should be defined in terms of "marked sub-expressions" not just by stating the effect it has on match_results objects.
On Tue, Jan 21, 2014 at 2:39 PM, Jonathan Wakely <jwakely@redhat.com> wrote: > OK, thanks for confirming that. In that case your patch is OK to > commit. Committed. > I'll raise a defect report against the standard as I don't think the > specification of nosubs is clear. If that's what it means then it > should be defined in terms of "marked sub-expressions" not just by > stating the effect it has on match_results objects. Thanks!
diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc index 1ceac60..73f55df 100644 --- a/libstdc++-v3/include/bits/regex.tcc +++ b/libstdc++-v3/include/bits/regex.tcc @@ -126,8 +126,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __suf.second = __e; __suf.matched = (__suf.first != __suf.second); } - if (__re.flags() & regex_constants::nosubs) - __res.resize(3); } return __ret; } diff --git a/libstdc++-v3/include/bits/regex_scanner.tcc b/libstdc++-v3/include/bits/regex_scanner.tcc index d954d07..5332d2e 100644 --- a/libstdc++-v3/include/bits/regex_scanner.tcc +++ b/libstdc++-v3/include/bits/regex_scanner.tcc @@ -139,6 +139,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION else __throw_regex_error(regex_constants::error_paren); } + else if (_M_flags & regex_constants::nosubs) + _M_token = _S_token_subexpr_no_group_begin; else _M_token = _S_token_subexpr_begin; } diff --git a/libstdc++-v3/testsuite/28_regex/constants/syntax_option_type.cc b/libstdc++-v3/testsuite/28_regex/constants/syntax_option_type.cc index 22559f5..2423775 100644 --- a/libstdc++-v3/testsuite/28_regex/constants/syntax_option_type.cc +++ b/libstdc++-v3/testsuite/28_regex/constants/syntax_option_type.cc @@ -1,5 +1,4 @@ // { dg-options "-std=c++0x" } -// { dg-do compile } // // 2009-06-17 Stephen M. Webb <stephen.webb@xandros.com> // @@ -23,6 +22,7 @@ // 28.5.1 #include <regex> +#include <testsuite_hooks.h> void test01() @@ -82,10 +82,21 @@ test04_constexpr() constexpr auto a3 __attribute__((unused)) = ~grep; } +void +test05() +{ + using namespace std; + using namespace regex_constants; + regex re("((a)(s))", nosubs | ECMAScript); + VERIFY(re.mark_count() == 0); +} + int main() { test01(); test02(); test03(); + test04_constexpr(); + test05(); return 0; }