Message ID | CAG4ZjN=QXU=1Jt2b95EbG7m7PZR==orYiXBWDHvbx9U9AxNktw@mail.gmail.com |
---|---|
State | New |
Headers | show |
On Wed, Jan 21, 2015 at 9:10 PM, Tim Shen <timshen@google.com> wrote:
> Submitted version.
I think this patch fits 4.9 branch well?
On Fri, Jan 23, 2015 at 1:20 PM, Tim Shen <timshen@google.com> wrote:
> I think this patch fits 4.9 branch well?
Ping.
On 23/01/15 13:20 -0800, Tim Shen wrote: >On Wed, Jan 21, 2015 at 9:10 PM, Tim Shen <timshen@google.com> wrote: >> Submitted version. > >I think this patch fits 4.9 branch well? I don't think this needs to go on the 4.9 branch, apparently I'm the only person who's noticed the problem. I expect it's quite rare to try using those functions with forward iterators.
On Mon, Feb 2, 2015 at 3:22 AM, Jonathan Wakely <jwakely@redhat.com> wrote: > I don't think this needs to go on the 4.9 branch, apparently I'm the > only person who's noticed the problem. I expect it's quite rare to try > using those functions with forward iterators. Sorry, I was not talking about the first patch which fixes the forward iterator problem, because it's already checked into 4.9; I'm suggesting the last one, who fixes the first one :)
On 02/02/15 11:18 -0800, Tim Shen wrote: >On Mon, Feb 2, 2015 at 3:22 AM, Jonathan Wakely <jwakely@redhat.com> wrote: >> I don't think this needs to go on the 4.9 branch, apparently I'm the >> only person who's noticed the problem. I expect it's quite rare to try >> using those functions with forward iterators. > >Sorry, I was not talking about the first patch which fixes the forward >iterator problem, because it's already checked into 4.9; I'm >suggesting the last one, who fixes the first one :) Oh, I forgot the first one was already checked in to 4.9 -- OK, the second one is needed too.
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e4eed67..099ad8b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2015-01-22 Tim Shen <timshen@google.com> + + PR libstdc++/64649 + * include/bits/regex.tcc (regex_traits<>::lookup_collatename, + regex_traits<>::lookup_classname): Correctly narrow input chars. + * testsuite/28_regex/traits/wchar_t/user_defined.cc: New testcase. + 2015-01-21 Jonathan Wakely <jwakely@redhat.com> * config/abi/pre/gnu.ver: Use [jmy] for size_t parameters. diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc index 3f16e66..aad56e0 100644 --- a/libstdc++-v3/include/bits/regex.tcc +++ b/libstdc++-v3/include/bits/regex.tcc @@ -269,7 +269,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "DEL", }; - string __s(__first, __last); + string __s; + for (; __first != __last; ++__first) + __s += __fctyp.narrow(*__first, 0); + for (const auto& __it : __collatenames) if (__s == __it) return string_type(1, __fctyp.widen( @@ -311,8 +314,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; string __s; - for (auto __cur = __first; __cur != __last; ++__cur) - __s += __fctyp.narrow(__fctyp.tolower(*__cur), '?'); + for (; __first != __last; ++__first) + __s += __fctyp.narrow(__fctyp.tolower(*__first), 0); for (const auto& __it : __classnames) if (__s == __it.first) diff --git a/libstdc++-v3/testsuite/28_regex/traits/wchar_t/user_defined.cc b/libstdc++-v3/testsuite/28_regex/traits/wchar_t/user_defined.cc index 16bcd6a..8c686be 100644 --- a/libstdc++-v3/testsuite/28_regex/traits/wchar_t/user_defined.cc +++ b/libstdc++-v3/testsuite/28_regex/traits/wchar_t/user_defined.cc @@ -55,8 +55,32 @@ test01() VERIFY(!regex_match(L"\u2029", re)); } +struct MyCtype : std::ctype<wchar_t> +{ + char + do_narrow(wchar_t c, char dflt) const override + { + if (c >= 256) + return dflt; + return ((char)c)+1; + } +}; + +void +test02() +{ + std::locale loc(std::locale(), new MyCtype); + std::regex_traits<wchar_t> traits; + traits.imbue(loc); + wchar_t wch = L'p'; + VERIFY(traits.lookup_collatename(&wch, &wch+1) == L"q"); + std::wstring ws = L"chfhs"; // chars of "digit" shifted by 1. + VERIFY(traits.lookup_classname(ws.begin(), ws.end()) != 0); +} + int main() { test01(); + test02(); return 0; }
On Wed, Jan 21, 2015 at 9:08 PM, Tim Shen <timshen@google.com> wrote: > Fixed and committed. Submitted version.