diff mbox series

Default special members of regex types and add noexcept

Message ID 20180608105942.GA5624@redhat.com
State New
Headers show
Series Default special members of regex types and add noexcept | expand

Commit Message

Jonathan Wakely June 8, 2018, 11:01 a.m. UTC
Nothing very exciting, just adding noexcept and defaulting some
members.

	* include/bits/regex.h (sub_match): Add noexcept to default
	constructor and length observer.
	(match_results): Add noexcept to default constructor and observers
	with no preconditions. Define destructor as defaulted.
	(operator==, operator!=, swap): Add noexcept.
	(regex_iterator): Add default member initializers and define default
	constructor and destructor as defaulted. Add noexcept to equality
	and dereference operators.

Tested powerpc64le-linux, committed to trunk.
commit 786d6b032ca5fb4dd0bbeaa3cf8024d04c6022ad
Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jun 7 08:56:45 2018 +0000

    Default special members of regex types and add noexcept
    
            * include/bits/regex.h (sub_match): Add noexcept to default
            constructor and length observer.
            (match_results): Add noexcept to default constructor and observers
            with no preconditions. Define destructor as defaulted.
            (operator==, operator!=, swap): Add noexcept.
            (regex_iterator): Add default member initializers and define default
            constructor and destructor as defaulted. Add noexcept to equality
            and dereference operators.

Comments

Stephan Bergmann June 26, 2018, 7:19 a.m. UTC | #1
On 08/06/18 13:01, Jonathan Wakely wrote:
> Nothing very exciting, just adding noexcept and defaulting some
> members.
> 
>      * include/bits/regex.h (sub_match): Add noexcept to default
>      constructor and length observer.
>      (match_results): Add noexcept to default constructor and observers
>      with no preconditions. Define destructor as defaulted.
>      (operator==, operator!=, swap): Add noexcept.
>      (regex_iterator): Add default member initializers and define default
>      constructor and destructor as defaulted. Add noexcept to equality
>      and dereference operators.
> 
> Tested powerpc64le-linux, committed to trunk.

Looks like that forgot to also add noexcept to the definition of

>     regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>::
>     operator==(const regex_iterator& __rhs) const

in libstdc++-v3/include/bits/regex.tcc?
Jonathan Wakely June 26, 2018, 12:24 p.m. UTC | #2
On 26/06/18 09:19 +0200, Stephan Bergmann wrote:
>On 08/06/18 13:01, Jonathan Wakely wrote:
>>Nothing very exciting, just adding noexcept and defaulting some
>>members.
>>
>>     * include/bits/regex.h (sub_match): Add noexcept to default
>>     constructor and length observer.
>>     (match_results): Add noexcept to default constructor and observers
>>     with no preconditions. Define destructor as defaulted.
>>     (operator==, operator!=, swap): Add noexcept.
>>     (regex_iterator): Add default member initializers and define default
>>     constructor and destructor as defaulted. Add noexcept to equality
>>     and dereference operators.
>>
>>Tested powerpc64le-linux, committed to trunk.
>
>Looks like that forgot to also add noexcept to the definition of
>
>>    regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>::
>>    operator==(const regex_iterator& __rhs) const
>
>in libstdc++-v3/include/bits/regex.tcc?

Indeed I did, thanks.

Tested x86_64-linux, committed to trunk.
commit a3371eeaf2434550934a95f4f41a2a9ae31ead81
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jun 26 13:01:56 2018 +0100

    Add missing noexcept on definition to match declaration
    
            * include/bits/regex.tcc (regex_iterator::operator==): Add missing
            noexcept.

diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc
index b92edb9ab29..dcf660902bc 100644
--- a/libstdc++-v3/include/bits/regex.tcc
+++ b/libstdc++-v3/include/bits/regex.tcc
@@ -500,7 +500,7 @@ namespace __detail
 	   typename _Rx_traits>
     bool
     regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>::
-    operator==(const regex_iterator& __rhs) const
+    operator==(const regex_iterator& __rhs) const noexcept
     {
       if (_M_pregex == nullptr && __rhs._M_pregex == nullptr)
 	return true;
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h
index 12e830b2c68..674be9ac50c 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -868,18 +868,18 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
     public:
       typedef typename __iter_traits::value_type      	value_type;
       typedef typename __iter_traits::difference_type 	difference_type;
-      typedef _BiIter				   iterator;
-      typedef std::basic_string<value_type>	     string_type;
+      typedef _BiIter					iterator;
+      typedef basic_string<value_type>			string_type;
 
       bool matched;
 
-      constexpr sub_match() : matched() { }
+      constexpr sub_match() noexcept : matched() { }
 
       /**
        * Gets the length of the matching sequence.
        */
       difference_type
-      length() const
+      length() const noexcept
       { return this->matched ? std::distance(this->first, this->second) : 0; }
 
       /**
@@ -1602,37 +1602,36 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @post size() returns 0 and str() returns an empty string.
        */
       explicit
-      match_results(const _Alloc& __a = _Alloc())
+      match_results(const _Alloc& __a = _Alloc()) noexcept
       : _Base_type(__a)
       { }
 
       /**
        * @brief Copy constructs a %match_results.
        */
-      match_results(const match_results& __rhs) = default;
+      match_results(const match_results&) = default;
 
       /**
        * @brief Move constructs a %match_results.
        */
-      match_results(match_results&& __rhs) noexcept = default;
+      match_results(match_results&&) noexcept = default;
 
       /**
        * @brief Assigns rhs to *this.
        */
       match_results&
-      operator=(const match_results& __rhs) = default;
+      operator=(const match_results&) = default;
 
       /**
        * @brief Move-assigns rhs to *this.
        */
       match_results&
-      operator=(match_results&& __rhs) = default;
+      operator=(match_results&&) = default;
 
       /**
        * @brief Destroys a %match_results object.
        */
-      ~match_results()
-      { }
+      ~match_results() = default;
 
       //@}
 
@@ -1642,7 +1641,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @retval true   The object has a fully-established result state.
        * @retval false  The object is not ready.
        */
-      bool ready() const { return !_Base_type::empty(); }
+      bool ready() const noexcept { return !_Base_type::empty(); }
 
       /**
        * @name 28.10.2 Size
@@ -1659,11 +1658,11 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @returns the number of matches found.
        */
       size_type
-      size() const
+      size() const noexcept
       { return _Base_type::empty() ? 0 : _Base_type::size() - 3; }
 
       size_type
-      max_size() const
+      max_size() const noexcept
       { return _Base_type::max_size(); }
 
       /**
@@ -1672,7 +1671,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @retval false The %match_results object is not empty.
        */
       bool
-      empty() const
+      empty() const noexcept
       { return size() == 0; }
 
       //@}
@@ -1776,28 +1775,28 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @brief Gets an iterator to the start of the %sub_match collection.
        */
       const_iterator
-      begin() const
+      begin() const noexcept
       { return _Base_type::begin(); }
 
       /**
        * @brief Gets an iterator to the start of the %sub_match collection.
        */
       const_iterator
-      cbegin() const
+      cbegin() const noexcept
       { return this->begin(); }
 
       /**
        * @brief Gets an iterator to one-past-the-end of the collection.
        */
       const_iterator
-      end() const
+      end() const noexcept
       { return _Base_type::end() - (empty() ? 0 : 3); }
 
       /**
        * @brief Gets an iterator to one-past-the-end of the collection.
        */
       const_iterator
-      cend() const
+      cend() const noexcept
       { return this->end(); }
 
       //@}
@@ -1872,7 +1871,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @brief Gets a copy of the allocator.
        */
       allocator_type
-      get_allocator() const
+      get_allocator() const noexcept
       { return _Base_type::get_allocator(); }
 
       //@}
@@ -1886,7 +1885,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @brief Swaps the contents of two match_results.
        */
       void
-      swap(match_results& __that)
+      swap(match_results& __that) noexcept
       {
 	using std::swap;
 	_Base_type::swap(__that);
@@ -1955,7 +1954,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
   template<typename _Bi_iter, typename _Alloc>
     inline bool
     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
-	       const match_results<_Bi_iter, _Alloc>& __m2)
+	       const match_results<_Bi_iter, _Alloc>& __m2) noexcept
     {
       if (__m1.ready() != __m2.ready())
 	return false;
@@ -1979,7 +1978,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
   template<typename _Bi_iter, class _Alloc>
     inline bool
     operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
-	       const match_results<_Bi_iter, _Alloc>& __m2)
+	       const match_results<_Bi_iter, _Alloc>& __m2) noexcept
     { return !(__m1 == __m2); }
 
   // [7.10.6] match_results swap
@@ -1993,7 +1992,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
   template<typename _Bi_iter, typename _Alloc>
     inline void
     swap(match_results<_Bi_iter, _Alloc>& __lhs,
-	 match_results<_Bi_iter, _Alloc>& __rhs)
+	 match_results<_Bi_iter, _Alloc>& __rhs) noexcept
     { __lhs.swap(__rhs); }
 
 _GLIBCXX_END_NAMESPACE_CXX11
@@ -2490,9 +2489,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
        * @brief Provides a singular iterator, useful for indicating
        * one-past-the-end of a range.
        */
-      regex_iterator()
-      : _M_pregex()
-      { }
+      regex_iterator() = default;
 
       /**
        * Constructs a %regex_iterator...
@@ -2515,42 +2512,41 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
 		     regex_constants::match_flag_type
 		     = regex_constants::match_default) = delete;
-      /**
-       * Copy constructs a %regex_iterator.
-       */
-      regex_iterator(const regex_iterator& __rhs) = default;
 
-      /**
-       * @brief Assigns one %regex_iterator to another.
-       */
+      /// Copy constructs a %regex_iterator.
+      regex_iterator(const regex_iterator&) = default;
+
+      /// Copy assigns one %regex_iterator to another.
       regex_iterator&
-      operator=(const regex_iterator& __rhs) = default;
+      operator=(const regex_iterator&) = default;
+
+      ~regex_iterator() = default;
 
       /**
        * @brief Tests the equivalence of two regex iterators.
        */
       bool
-      operator==(const regex_iterator& __rhs) const;
+      operator==(const regex_iterator&) const noexcept;
 
       /**
        * @brief Tests the inequivalence of two regex iterators.
        */
       bool
-      operator!=(const regex_iterator& __rhs) const
+      operator!=(const regex_iterator& __rhs) const noexcept
       { return !(*this == __rhs); }
 
       /**
        * @brief Dereferences a %regex_iterator.
        */
       const value_type&
-      operator*() const
+      operator*() const noexcept
       { return _M_match; }
 
       /**
        * @brief Selects a %regex_iterator member.
        */
       const value_type*
-      operator->() const
+      operator->() const noexcept
       { return &_M_match; }
 
       /**
@@ -2571,10 +2567,10 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       }
 
     private:
-      _Bi_iter				_M_begin;
-      _Bi_iter				_M_end;
-      const regex_type*			_M_pregex;
-      regex_constants::match_flag_type	_M_flags;
+      _Bi_iter				_M_begin {};
+      _Bi_iter				_M_end {};
+      const regex_type*			_M_pregex = nullptr;
+      regex_constants::match_flag_type	_M_flags {};
       match_results<_Bi_iter>		_M_match;
     };