regex.h (regex_token_iterator<>::regex_token_iterator): Fix initialization orders...
authorTim Shen <timshen91@gmail.com>
Thu, 17 Oct 2013 20:46:50 +0000 (20:46 +0000)
committerTim Shen <timshen@gcc.gnu.org>
Thu, 17 Oct 2013 20:46:50 +0000 (20:46 +0000)
2013-10-17  Tim Shen  <timshen91@gmail.com>

* include/bits/regex.h (regex_token_iterator<>::regex_token_iterator):
Fix initialization orders in initialization list and add explicit braces
for potentially ambiguous(actually not) `else` branch to eliminate
warnings.
* include/bits/regex_automaton.h (_NFA<>::_NFA): Likewise.
* include/bits/regex_compiler.h (_CharMatcher<>::_CharMatcher,
_BracketMatcher<>::_BracketMatcher): Likewise.
* include/bits/regex_compiler.tcc (_Compiler<>::_Compiler,
_Compiler<>::_M_atom): Likewise.
* include/bits/regex_executor.h (_Executor<>::_Executor): Likewise.
* include/bits/regex_executor.tcc (_DFSExecutor<>::_M_dfs,
_Executor<>::_M_word_boundry): Likewise.
* include/bits/regex_scanner.tcc (_Scanner<>::_Scanner,
_Scanner<>::_M_eat_class): Likewise.
* include/bits/regex.tcc (__regex_algo_impl<>,
regex_iterator<>::operator++): Likewise, and remove unused typedef.

From-SVN: r203798

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/regex.h
libstdc++-v3/include/bits/regex.tcc
libstdc++-v3/include/bits/regex_automaton.h
libstdc++-v3/include/bits/regex_compiler.h
libstdc++-v3/include/bits/regex_compiler.tcc
libstdc++-v3/include/bits/regex_executor.h
libstdc++-v3/include/bits/regex_executor.tcc
libstdc++-v3/include/bits/regex_scanner.tcc

index 80abfa8da1c0ed7291e05e8be71b126b810bc9e7..5ae46af37811514117dece310b723107a2da0120 100644 (file)
@@ -1,3 +1,22 @@
+2013-10-17  Tim Shen  <timshen91@gmail.com>
+
+       * include/bits/regex.h (regex_token_iterator<>::regex_token_iterator):
+       Fix initialization orders in initialization list and add explicit braces
+       for potentially ambiguous(actually not) `else` branch to eliminate
+       warnings.
+       * include/bits/regex_automaton.h (_NFA<>::_NFA): Likewise.
+       * include/bits/regex_compiler.h (_CharMatcher<>::_CharMatcher,
+       _BracketMatcher<>::_BracketMatcher): Likewise.
+       * include/bits/regex_compiler.tcc (_Compiler<>::_Compiler,
+       _Compiler<>::_M_atom): Likewise.
+       * include/bits/regex_executor.h (_Executor<>::_Executor): Likewise.
+       * include/bits/regex_executor.tcc (_DFSExecutor<>::_M_dfs,
+       _Executor<>::_M_word_boundry): Likewise.
+       * include/bits/regex_scanner.tcc (_Scanner<>::_Scanner,
+       _Scanner<>::_M_eat_class): Likewise.
+       * include/bits/regex.tcc (__regex_algo_impl<>,
+       regex_iterator<>::operator++): Likewise, and remove unused typedef.
+
 2013-10-16  Tim Shen  <timshen91@gmail.com>
 
        * include/bits/regex.h (regex_token_iterator<>::regex_token_iterator):
index 172ea8303f64e0577a325dd4e549cff97742334e..5d1a8f4b71ed82b5dafca809e995ae42a7755c64 100644 (file)
@@ -2514,7 +2514,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
        * iterator of the same type.
        */
       regex_token_iterator()
-      : _M_position(), _M_result(nullptr), _M_suffix(), _M_n(0), _M_subs(),
+      : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
       _M_has_m1(false)
       { }
 
@@ -2601,7 +2601,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
        */
       regex_token_iterator(const regex_token_iterator& __rhs)
       : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
-      _M_n(__rhs._M_n), _M_result(__rhs._M_result), _M_suffix(__rhs._M_suffix),
+      _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)
@@ -2679,10 +2679,10 @@ _GLIBCXX_END_NAMESPACE_VERSION
       { return _M_result == nullptr; }
 
       _Position         _M_position;
-      const value_type* _M_result;
+      std::vector<int>  _M_subs;
       value_type        _M_suffix;
       std::size_t       _M_n;
-      std::vector<int>  _M_subs;
+      const value_type* _M_result;
 
       // Show whether _M_subs contains -1
       bool              _M_has_m1;
index 0576422b5d91900e6d67a9b7436d1b0cbb42de05..b3b5314d744d9696ca5f8c37c29901355b6f2c24 100644 (file)
@@ -61,14 +61,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       for (auto& __it : __res)
        __it.matched = false;
 
-      typedef std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>>
-       _ExecutorPtr;
-      typedef _DFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _DFSExecutorT;
-      typedef _BFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _BFSExecutorT;
-
-      _ExecutorPtr __executor =
-       __get_executor<_BiIter, _Alloc, _CharT, _TraitsT,
-         __policy>(__s, __e, __res, __re, __flags);
+      auto __executor = __get_executor<_BiIter, _Alloc, _CharT, _TraitsT,
+          __policy>(__s, __e, __res, __re, __flags);
 
       bool __ret;
       if (__match_mode)
@@ -540,26 +534,29 @@ _GLIBCXX_END_NAMESPACE_VERSION
          auto __start = _M_match[0].second;
          auto __prefix_first = _M_match[0].second;
          if (_M_match[0].first == _M_match[0].second)
-           if (__start == _M_end)
-             {
-               _M_match = value_type();
-               return *this;
-             }
-           else
-             {
-               if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags
-                                | regex_constants::match_not_null
-                                | regex_constants::match_continuous))
-                 {
-                   _GLIBCXX_DEBUG_ASSERT(_M_match[0].matched);
-                   _M_match.at(_M_match.size()).first = __prefix_first;
-                   _M_match._M_in_iterator = true;
-                   _M_match._M_begin = _M_begin;
-                   return *this;
-                 }
-               else
-                 ++__start;
-             }
+           {
+             if (__start == _M_end)
+               {
+                 _M_match = value_type();
+                 return *this;
+               }
+             else
+               {
+                 if (regex_search(__start, _M_end, _M_match, *_M_pregex,
+                                  _M_flags
+                                  | regex_constants::match_not_null
+                                  | regex_constants::match_continuous))
+                   {
+                     _GLIBCXX_DEBUG_ASSERT(_M_match[0].matched);
+                     _M_match.at(_M_match.size()).first = __prefix_first;
+                     _M_match._M_in_iterator = true;
+                     _M_match._M_begin = _M_begin;
+                     return *this;
+                   }
+                 else
+                   ++__start;
+               }
+           }
          _M_flags |= regex_constants::match_prev_avail;
          if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
            {
index 35cfc1be92f94149ca7749ec304ddbe804b9de5a..cb944990b4912ef45827ceeba29d19a487798f19 100644 (file)
@@ -138,7 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       _NFA(_FlagT __f)
       : _M_flags(__f), _M_start_state(0), _M_subexpr_count(0),
-      _M_has_backref(false), _M_quant_count(0)
+      _M_quant_count(0), _M_has_backref(false)
       { }
 
       _FlagT
index 297fe3f60e9be8daaeb1a5fb20822e000835f8df..7e4e6adafd56f8d2f25fd0c0accb6a79853d3229 100644 (file)
@@ -156,7 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       _CharMatcher(_CharT __ch, const _TraitsT& __traits, _FlagT __flags)
-      : _M_ch(_M_translate(__ch)), _M_traits(__traits), _M_flags(__flags)
+      : _M_traits(__traits), _M_flags(__flags), _M_ch(_M_translate(__ch))
       { }
 
       bool
@@ -189,8 +189,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _BracketMatcher(bool __is_non_matching,
                      const _TraitsT& __traits,
                      _FlagT __flags)
-      : _M_is_non_matching(__is_non_matching), _M_traits(__traits),
-       _M_flags(__flags), _M_class_set(0)
+      : _M_traits(__traits), _M_class_set(0), _M_flags(__flags),
+      _M_is_non_matching(__is_non_matching)
       { }
 
       bool
index 52386ce4e6450546cf618fff8eed4f9fa5f689d7..e3764b8d82aa1511bef91569f1184a1c3fcf2512 100644 (file)
@@ -73,8 +73,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
               ? __flags
               : __flags | regex_constants::ECMAScript),
     _M_traits(__traits),
-    _M_scanner(__b, __e, _M_flags, _M_traits.getloc()),
     _M_ctype(std::use_facet<std::ctype<_CharT>>(_M_traits.getloc())),
+    _M_scanner(__b, __e, _M_flags, _M_traits.getloc()),
     _M_nfa(_M_flags)
     {
       _StateSeqT __r(_M_nfa, _M_nfa._M_start());
@@ -318,7 +318,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
       else if (_M_match_token(_ScannerT::_S_token_subexpr_begin))
        {
-         auto __mark = _M_nfa._M_sub_count();
          _StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin());
          this->_M_disjunction();
          if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
index 23b5d011545ce4d05c539c9985b5ae9742c25df9..018b649a25aef1cacdc7973e9286a7492ff2e968 100644 (file)
@@ -74,8 +74,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                _FlagT          __flags)
       : _M_begin(__begin),
       _M_end(__end),
-      _M_results(__results),
       _M_re(__re),
+      _M_results(__results),
       _M_flags((__flags & regex_constants::match_prev_avail)
               ? (__flags
                  & ~regex_constants::match_not_bol
index 59b082e2ac3be1f89c5dde02a558a149ed55bf53..b8755736e607d0135a228834c70d3c0bf0537955 100644 (file)
@@ -145,15 +145,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            if (this->_M_re._M_traits.transform(__submatch.first,
                                                __submatch.second)
                == this->_M_re._M_traits.transform(__current, __last))
-             if (__last != __current)
-               {
-                 auto __backup = __current;
-                 __current = __last;
+             {
+               if (__last != __current)
+                 {
+                   auto __backup = __current;
+                   __current = __last;
+                   __ret = _M_dfs(__state._M_next);
+                   __current = __backup;
+                 }
+               else
                  __ret = _M_dfs(__state._M_next);
-                 __current = __backup;
-               }
-             else
-               __ret = _M_dfs(__state._M_next);
+             }
          }
          break;
        case _S_opcode_accept:
@@ -353,15 +355,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       auto __pre = _M_current;
       --__pre;
       if (!(_M_at_begin() && _M_at_end()))
-       if (_M_at_begin())
-         __ans = _M_is_word(*_M_current)
-           && !(_M_flags & regex_constants::match_not_bow);
-       else if (_M_at_end())
-         __ans = _M_is_word(*__pre)
-           && !(_M_flags & regex_constants::match_not_eow);
-       else
-         __ans = _M_is_word(*_M_current)
-           != _M_is_word(*__pre);
+       {
+         if (_M_at_begin())
+           __ans = _M_is_word(*_M_current)
+             && !(_M_flags & regex_constants::match_not_bow);
+         else if (_M_at_end())
+           __ans = _M_is_word(*__pre)
+             && !(_M_flags & regex_constants::match_not_eow);
+         else
+           __ans = _M_is_word(*_M_current)
+             != _M_is_word(*__pre);
+       }
       return __ans;
     }
 
index fc8273878ce5d4f01d06870e63fc4bbca4ce7e15..21d1e91f5f72ec5c203390c4e9240693ae517954 100644 (file)
@@ -56,8 +56,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _Scanner<_FwdIter>::
     _Scanner(_FwdIter __begin, _FwdIter __end,
             _FlagT __flags, std::locale __loc)
-    : _M_current(__begin) , _M_end(__end) , _M_flags(__flags),
-      _M_ctype(std::use_facet<_CtypeT>(__loc)), _M_state(_S_state_normal),
+    : _M_state(_S_state_normal), _M_current(__begin), _M_end(__end),
+      _M_flags(__flags),
+      _M_ctype(std::use_facet<_CtypeT>(__loc)),
       _M_at_bracket_start(false),
       _M_token_map
        {
@@ -94,9 +95,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          {'t', '\t'},
          {'v', '\v'},
        },
-      _M_escape_map(_M_is_ecma()
-                   ? _M_ecma_escape_map
-                   : _M_awk_escape_map),
       _M_ecma_spec_char
        {
          '^',
@@ -138,14 +136,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          '^',
          '$',
        },
-      _M_eat_escape(_M_is_ecma()
-                   ? &_Scanner::_M_eat_escape_ecma
-                   : &_Scanner::_M_eat_escape_posix),
+      _M_escape_map(_M_is_ecma()
+                   ? _M_ecma_escape_map
+                   : _M_awk_escape_map),
       _M_spec_char(_M_is_ecma()
                   ? _M_ecma_spec_char
                   : _M_is_basic()
                   ? _M_basic_spec_char
-                  : _M_extended_spec_char)
+                  : _M_extended_spec_char),
+      _M_eat_escape(_M_is_ecma()
+                   ? &_Scanner::_M_eat_escape_ecma
+                   : &_Scanner::_M_eat_escape_posix)
     { _M_advance(); }
 
   template<typename _FwdIter>
@@ -243,9 +244,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          _M_state = _S_state_in_brace;
          _M_token = _S_token_interval_begin;
        }
-      else if (_M_spec_char.count(__c)
-              && __c != ']'
-              && __c != '}'
+      else if ((_M_spec_char.count(__c)
+               && __c != ']'
+               && __c != '}')
               || (_M_is_grep() && __c == '\n'))
        _M_token = _M_token_map.at(__c);
       else
@@ -515,10 +516,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          || *_M_current++ != __ch
          || _M_current == _M_end // skip __ch
          || *_M_current++ != ']') // skip ']'
-       if (__ch == ':')
-         __throw_regex_error(regex_constants::error_ctype);
-       else
-         __throw_regex_error(regex_constants::error_collate);
+       {
+         if (__ch == ':')
+           __throw_regex_error(regex_constants::error_ctype);
+         else
+           __throw_regex_error(regex_constants::error_collate);
+       }
     }
 
 #ifdef _GLIBCXX_DEBUG