From 1d9fec7937f45dde5e04cac966a2d9a12f2fc15a Mon Sep 17 00:00:00 2001 From: Yiran Wang Date: Tue, 23 Jun 2015 15:33:17 -0700 Subject: Synchronize with google/gcc-4_9 to r224707 (from r214835) Change-Id: I3d6f06fc613c8f8b6a82143dc44b7338483aac5d --- gcc-4.9/libstdc++-v3/include/bits/regex.h | 137 +++++++++++++++++------------- 1 file changed, 79 insertions(+), 58 deletions(-) (limited to 'gcc-4.9/libstdc++-v3/include/bits/regex.h') diff --git a/gcc-4.9/libstdc++-v3/include/bits/regex.h b/gcc-4.9/libstdc++-v3/include/bits/regex.h index e556350..b358c79 100644 --- a/gcc-4.9/libstdc++-v3/include/bits/regex.h +++ b/gcc-4.9/libstdc++-v3/include/bits/regex.h @@ -474,17 +474,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * @param __rhs A @p regex object. */ - basic_regex(const basic_regex& __rhs) = default; + basic_regex(const basic_regex& __rhs) + : _M_flags(__rhs._M_flags), _M_original_str(__rhs._M_original_str) + { + _M_traits.imbue(__rhs.getloc()); + this->assign(_M_original_str, _M_flags); + } /** * @brief Move-constructs a basic regular expression. * * @param __rhs A @p regex object. + * + * The implementation is a workaround concerning ABI compatibility. See: + * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html */ - basic_regex(const basic_regex&& __rhs) noexcept - : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits), - _M_automaton(std::move(__rhs._M_automaton)) - { } + basic_regex(basic_regex&& __rhs) + : _M_flags(__rhs._M_flags), + _M_original_str(std::move(__rhs._M_original_str)) + { + _M_traits.imbue(__rhs.getloc()); + this->assign(_M_original_str, _M_flags); + __rhs._M_automaton.reset(); + } /** * @brief Constructs a basic regular expression from the string @@ -555,9 +567,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /** * @brief Move-assigns one regular expression to another. + * + * The implementation is a workaround concerning ABI compatibility. See: + * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html */ basic_regex& - operator=(basic_regex&& __rhs) noexcept + operator=(basic_regex&& __rhs) { return this->assign(std::move(__rhs)); } /** @@ -591,8 +606,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION basic_regex& assign(const basic_regex& __rhs) { - basic_regex __tmp(__rhs); - this->swap(__tmp); + _M_flags = __rhs._M_flags; + _M_original_str = __rhs._M_original_str; + _M_traits.imbue(__rhs.getloc()); + this->assign(_M_original_str, _M_flags); return *this; } @@ -600,12 +617,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @brief The move-assignment operator. * * @param __rhs Another regular expression object. + * + * The implementation is a workaround concerning ABI compatibility. See: + * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html */ basic_regex& - assign(basic_regex&& __rhs) noexcept + assign(basic_regex&& __rhs) { - basic_regex __tmp(std::move(__rhs)); - this->swap(__tmp); + _M_flags = __rhs._M_flags; + _M_original_str = std::move(__rhs._M_original_str); + __rhs._M_automaton.reset(); + _M_traits.imbue(__rhs.getloc()); + this->assign(_M_original_str, _M_flags); return *this; } @@ -659,12 +682,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s, flag_type __flags = ECMAScript) { + _M_automaton = __detail::__compile_nfa( + __s.data(), __s.data() + __s.size(), _M_traits, __flags); + _M_original_str = __s; _M_flags = __flags; - _M_original_str.assign(__s.begin(), __s.end()); - auto __p = _M_original_str.c_str(); - _M_automaton = __detail::__compile_nfa(__p, - __p + _M_original_str.size(), - _M_traits, _M_flags); return *this; } @@ -709,7 +730,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ unsigned int mark_count() const - { return _M_automaton->_M_sub_count() - 1; } + { + if (_M_automaton) + return _M_automaton->_M_sub_count() - 1; + return 0; + } /** * @brief Gets the flags used to construct the regular expression @@ -728,9 +753,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION locale_type imbue(locale_type __loc) { - auto __ret = _M_traits.imbue(__loc); - this->assign(_M_original_str, _M_flags); - return __ret; + _M_automaton = nullptr; + return _M_traits.imbue(__loc); } /** @@ -752,7 +776,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::swap(_M_flags, __rhs._M_flags); std::swap(_M_traits, __rhs._M_traits); - std::swap(_M_automaton, __rhs._M_automaton); + auto __tmp = std::move(_M_original_str); + this->assign(__rhs._M_original_str, _M_flags); + __rhs.assign(__tmp, __rhs._M_flags); } #ifdef _GLIBCXX_DEBUG @@ -761,7 +787,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _M_automaton->_M_dot(__ostr); } #endif - protected: + private: typedef std::shared_ptr<__detail::_NFA<_Rx_traits>> _AutomatonPtr; templateprefix().first, - (*this)[__sub].first) : -1; + return __sub < size() ? std::distance(_M_begin, + (*this)[__sub].first) : -1; } /** @@ -1762,7 +1771,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ const_iterator cbegin() const - { return _Base_type::cbegin() + 2; } + { return this->begin(); } /** * @brief Gets an iterator to one-past-the-end of the collection. @@ -1776,7 +1785,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ const_iterator cend() const - { return _Base_type::cend(); } + { return this->end(); } //@} @@ -1814,7 +1823,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /** * @pre ready() == true */ - template + template basic_string format(const basic_string& __fmt, match_flag_type __flags = regex_constants::format_default) const @@ -1865,7 +1874,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ void swap(match_results& __that) - { _Base_type::swap(__that); } + { + using std::swap; + _Base_type::swap(__that); + swap(_M_begin, __that._M_begin); + } //@} private: @@ -2604,7 +2617,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION regex_constants::match_flag_type __m = regex_constants::match_default) : _M_position(__a, __b, __re, __m), - _M_subs(__submatches, *(&__submatches+1)), _M_n(0) + _M_subs(__submatches, __submatches + _Nm), _M_n(0) { _M_init(__a, __b); } /** @@ -2613,12 +2626,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ regex_token_iterator(const regex_token_iterator& __rhs) : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs), - _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_result(__rhs._M_result), - _M_has_m1(__rhs._M_has_m1) - { - if (__rhs._M_result == &__rhs._M_suffix) - _M_result = &_M_suffix; - } + _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1) + { _M_normalize_result(); } /** * @brief Assigns a %regex_token_iterator to another. @@ -2687,9 +2696,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } constexpr bool - _M_end_of_seq() + _M_end_of_seq() const { return _M_result == nullptr; } + // [28.12.2.2.4] + void + _M_normalize_result() + { + if (_M_position != _Position()) + _M_result = &_M_current_match(); + else if (_M_has_m1) + _M_result = &_M_suffix; + else + _M_result = nullptr; + } + _Position _M_position; std::vector _M_subs; value_type _M_suffix; -- cgit v1.1