From patchwork Fri Jun 8 11:01:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 926680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-479325-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NTXyk1At"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 412KGn1XxKz9s1B for ; Fri, 8 Jun 2018 21:01:37 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=OXQ+rgmG/QM+HOOrsGj3754beQBU4Z/jn7QAB3bij5BV7Fl2Sdzua 7dWypqG/lx0yLkq9F8+o762LmUNfqUqnxua23VggRfrNjqm7bZAdRhywfzuNQoXW QZnFCXDjOYRJfOcOxd9TlT2/nHLiM3Nok6I/xrze/tliA2CDgJi0mg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=+hh9kaZzd9YmGoSEesh//s4Dm1Y=; b=NTXyk1AtMH5cgDHZqRxS BlMBBmvrSRSmoU4GUw0/GvhVLQymxFnJurkjNo3h1kTd+qeMOoLi8d2HKBsSX3Rk YBj+RKm510RWpgOJk/iZJxkPOnERFP7Hw7V1Nja8kaYRHswVIOtnvnOCJGzHVVDo M5gd2pe2rTl58XjC3ZnE6YQ= Received: (qmail 57566 invoked by alias); 8 Jun 2018 11:01:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 57547 invoked by uid 89); 8 Jun 2018 11:01:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=observer X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Jun 2018 11:01:18 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF757401EF04; Fri, 8 Jun 2018 11:01:16 +0000 (UTC) Received: from localhost (unknown [10.33.36.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 337D41C722; Fri, 8 Jun 2018 11:01:16 +0000 (UTC) Date: Fri, 8 Jun 2018 12:01:15 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Default special members of regex types and add noexcept Message-ID: <20180608105942.GA5624@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) 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 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. 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 string_type; + typedef _BiIter iterator; + typedef basic_string 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 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 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 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; };