https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85824

--- Comment #5 from Tim Shen <timshen at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> Tim, I'll take care of checking errno in collate<>::_M_transform but could
> you advise what to do about the regex compiler? Maybe:
> 
> --- a/libstdc++-v3/include/bits/regex.h
> +++ b/libstdc++-v3/include/bits/regex.h
> @@ -257,7 +257,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
>           const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
>           std::vector<char_type> __s(__first, __last);
>           __fctyp.tolower(__s.data(), __s.data() + __s.size());
> -         return this->transform(__s.data(), __s.data() + __s.size());
> +         __try {
> +           return this->transform(__s.data(), __s.data() + __s.size());
> +         } catch(const std::runtime_error&) {
> +           return string_type();
> +         }
>         }
>  
>        /**

First of all, std::regex("[0-9]") shouldn't be locale sensitive, as
regex_constants::collate is set. If somehow a locale-related exception was
thrown without collate being set, it's a bug in the regex implementation and we
should fix it. We probably have a bug in _BracketMatcher::_M_apply().

When collate is set, we still don't want to eagerly forward exceptions in regex
ctor. I think regex_traits<>::transform_primary should be exception neutral
(unless it's specified otherwise). Instead, we some how fix regex's constructor
not to generate exceptions from _BracketMatcher::_M_make_cache().

Regarding the compile-time variable __collate in _BracketMatcher, I suggest to
fix _BracketMatcher to the following definition:
* If !__collate or -fno-exceptions, nothing needs to be changed; otherwise
* change the element of cache from bool to a 3-state enum, e.g. enum { MATCHED,
NOT_MATCHED, NOT_CACHED }. When an exception happens in _M_make_cache, catch it
and set the cache result to NOT_CACHED. During regex matching, non-cached
result requires a full run of _M_apply() and it likely throws.

Reply via email to