From: Tim Shen Date: Thu, 22 Jan 2015 05:02:38 +0000 (+0000) Subject: re PR libstdc++/64649 (regex_traits::lookup_classname() only works with random access... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=77033d2668248d1050d27ea57a8e85a1b3740ac8;p=gcc.git re PR libstdc++/64649 (regex_traits::lookup_classname() only works with random access iterators) 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. From-SVN: r219986 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e4eed670a25..099ad8b853a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2015-01-22 Tim Shen + + 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 * 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 3f16e66ab2a..aad56e08c8c 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 16bcd6a649a..8c686beaf1f 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 +{ + 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 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; }