From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4EAE13858418 for ; Tue, 27 Feb 2024 11:45:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EAE13858418 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4EAE13858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034341; cv=none; b=RNCts/dM4Is5pGqbMzSuZ2Mdy9HWvoFnPYqOP96WYB0zt3hKJzX2qvGi+OpdH6x+rzhjChvKjd9/CsOwZDkNLznTvw/hvdCsaHkIAQQOY41a4aBddO4Qo224bO52sJu2fm0Vq9gf1D+RDuSbaNWnv7DrIFLjO5URTwB0T3kI2Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034341; c=relaxed/simple; bh=VwWeD59+FY10W73sqjLP+RYFGQGbt+uy6VD3Hw5G7Vg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RF4Wv96qRmMvU03RhbQXbQm3PvI45NabPmxScDRHrWzEUrxIk2Xz1XqeeHGAJfmPAe67thnen0iOm8kaptaDJzhGOkcEXXWWMDUc5jvg75P0LoRyoP8pM38j3DXnubEloxWzjvtECapLVjgFIrOY2NUi+Gkfm6bvNTH0jdfUvGQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ezSRQ2XdgtvQNQzM+UnmAJp98YgTLmCKrMRdNCa4UQo=; b=ElCEn2eXvODElHFXbTxXUH848o+jeULeRaYJ2dDCP+TaVbbq5vCGlS1os1yqcehDzAA+Pc vqCuUamuxlutkB9/FIso2KUpZfDPB5rFL41XcyPGDuHUQLlMIuQOQqFIao5f+Br+e5oHs5 poqq/ro0ioKlQtgDmA4AC20QeYQgqUg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668--z8aVpnfPIq1Fd9kNpO3Lg-1; Tue, 27 Feb 2024 06:45:33 -0500 X-MC-Unique: -z8aVpnfPIq1Fd9kNpO3Lg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08BF528B6980; Tue, 27 Feb 2024 11:45:33 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AF342026D0A; Tue, 27 Feb 2024 11:45:32 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 5/8] libstdc++: Consistently use noexcept, constexpr, nodiscard on bitmask ops Date: Tue, 27 Feb 2024 11:42:02 +0000 Message-ID: <20240227114528.1350601-5-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Reviews invited. -- >8 -- The bitwise operators for combining bitmask types such as std::launch are not consistently annotated with noexcept, constexpr, and nodiscard. This is the subject of LWG 3977, although the proposed resolution doesn't work. We can make the changes in libstdc++ anyway though. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (operator|, operator&): Add noexcept. * include/bits/fs_fwd.h (operator&, operator|, operator^) (operator~): Add nodiscard to overloads for copy_options, perms, perm_options, and directory_options. * include/bits/ios_base.h (operator&, operator|, operator^) (operator~): Add nodiscard and noexcept to overloads for _Ios_Fmtflags, _Ios_Openmode, and _Ios_Iostate. (operator|=, operator&=, operator^=): Add constexpr for C++14. * include/bits/regex_constants.h (operator&, operator|, operator^) (operator~): Add nodiscard and noexcept to overloads for syntax_option_type and match_flag_type. (operator|=, operator&=, operator^=): Add noexcept. * include/std/charconv (operator&, operator|, operator^) (operator~): Add nodiscard to overloads for chars_format. * include/std/future (operator&, operator|, operator^) (operator~): Add nodiscard for overloads for launch. (operator&=, operator|=, operator^=): Add constexpr for C++14. * include/experimental/bits/fs_fwd.h (operator&, operator|) (operator^, operator~): Add nodiscard to overloads for copy_options, perms, and directory_options. * testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc: Add dg-warning for nodiscard warnings. * testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc: Likewise. * testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc: Likewise. * testsuite/27_io/filesystem/operations/bitmask_types.cc: New test. --- libstdc++-v3/include/bits/atomic_base.h | 4 +- libstdc++-v3/include/bits/fs_fwd.h | 16 ++++ libstdc++-v3/include/bits/ios_base.h | 89 ++++++++++++------- libstdc++-v3/include/bits/regex_constants.h | 52 ++++++----- .../include/experimental/bits/fs_fwd.h | 12 +++ libstdc++-v3/include/std/charconv | 4 + libstdc++-v3/include/std/future | 7 ++ .../filesystem/operations/bitmask_types.cc | 56 ++++++++++++ .../types/fmtflags/bitmask_operators.cc | 4 + .../types/iostate/bitmask_operators.cc | 4 + .../types/openmode/bitmask_operators.cc | 4 + 11 files changed, 194 insertions(+), 58 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/filesystem/operations/bitmask_types.cc diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index d3a2c4f3805..b857b441169 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -100,13 +100,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// @endcond constexpr memory_order - operator|(memory_order __m, __memory_order_modifier __mod) + operator|(memory_order __m, __memory_order_modifier __mod) noexcept { return memory_order(int(__m) | int(__mod)); } constexpr memory_order - operator&(memory_order __m, __memory_order_modifier __mod) + operator&(memory_order __m, __memory_order_modifier __mod) noexcept { return memory_order(int(__m) & int(__mod)); } diff --git a/libstdc++-v3/include/bits/fs_fwd.h b/libstdc++-v3/include/bits/fs_fwd.h index 6208e799b84..7e2bc30df30 100644 --- a/libstdc++-v3/include/bits/fs_fwd.h +++ b/libstdc++-v3/include/bits/fs_fwd.h @@ -91,6 +91,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @{ /// @relates copy_options + [[nodiscard]] constexpr copy_options operator&(copy_options __x, copy_options __y) noexcept { @@ -99,6 +100,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) & static_cast<__utype>(__y)); } + [[nodiscard]] constexpr copy_options operator|(copy_options __x, copy_options __y) noexcept { @@ -107,6 +109,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) | static_cast<__utype>(__y)); } + [[nodiscard]] constexpr copy_options operator^(copy_options __x, copy_options __y) noexcept { @@ -115,6 +118,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); } + [[nodiscard]] constexpr copy_options operator~(copy_options __x) noexcept { @@ -161,6 +165,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @{ /// @relates perms + [[nodiscard]] constexpr perms operator&(perms __x, perms __y) noexcept { @@ -169,6 +174,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) & static_cast<__utype>(__y)); } + [[nodiscard]] constexpr perms operator|(perms __x, perms __y) noexcept { @@ -177,6 +183,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) | static_cast<__utype>(__y)); } + [[nodiscard]] constexpr perms operator^(perms __x, perms __y) noexcept { @@ -185,6 +192,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); } + [[nodiscard]] constexpr perms operator~(perms __x) noexcept { @@ -215,6 +223,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @{ /// @relates perm_options + [[nodiscard]] constexpr perm_options operator&(perm_options __x, perm_options __y) noexcept { @@ -223,6 +232,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) & static_cast<__utype>(__y)); } + [[nodiscard]] constexpr perm_options operator|(perm_options __x, perm_options __y) noexcept { @@ -231,6 +241,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) | static_cast<__utype>(__y)); } + [[nodiscard]] constexpr perm_options operator^(perm_options __x, perm_options __y) noexcept { @@ -239,6 +250,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); } + [[nodiscard]] constexpr perm_options operator~(perm_options __x) noexcept { @@ -266,6 +278,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @{ /// @relates directory_options + [[nodiscard]] constexpr directory_options operator&(directory_options __x, directory_options __y) noexcept { @@ -274,6 +287,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) & static_cast<__utype>(__y)); } + [[nodiscard]] constexpr directory_options operator|(directory_options __x, directory_options __y) noexcept { @@ -282,6 +296,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) | static_cast<__utype>(__y)); } + [[nodiscard]] constexpr directory_options operator^(directory_options __x, directory_options __y) noexcept { @@ -290,6 +305,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); } + [[nodiscard]] constexpr directory_options operator~(directory_options __x) noexcept { diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index f0019649c3d..b69151c49ad 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -79,32 +79,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _S_ios_fmtflags_min = ~__INT_MAX__ }; - inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags - operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Fmtflags + operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW { return _Ios_Fmtflags(static_cast(__a) & static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags - operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Fmtflags + operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW { return _Ios_Fmtflags(static_cast(__a) | static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags - operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Fmtflags + operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW { return _Ios_Fmtflags(static_cast(__a) ^ static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags - operator~(_Ios_Fmtflags __a) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Fmtflags + operator~(_Ios_Fmtflags __a) _GLIBCXX_NOTHROW { return _Ios_Fmtflags(~static_cast(__a)); } + _GLIBCXX14_CONSTEXPR inline const _Ios_Fmtflags& - operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) + operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW { return __a = __a | __b; } + _GLIBCXX14_CONSTEXPR inline const _Ios_Fmtflags& - operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) + operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW { return __a = __a & __b; } + _GLIBCXX14_CONSTEXPR inline const _Ios_Fmtflags& - operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) + operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW { return __a = __a ^ __b; } @@ -122,32 +129,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _S_ios_openmode_min = ~__INT_MAX__ }; - inline _GLIBCXX_CONSTEXPR _Ios_Openmode - operator&(_Ios_Openmode __a, _Ios_Openmode __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Openmode + operator&(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW { return _Ios_Openmode(static_cast(__a) & static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Openmode - operator|(_Ios_Openmode __a, _Ios_Openmode __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Openmode + operator|(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW { return _Ios_Openmode(static_cast(__a) | static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Openmode - operator^(_Ios_Openmode __a, _Ios_Openmode __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Openmode + operator^(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW { return _Ios_Openmode(static_cast(__a) ^ static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Openmode - operator~(_Ios_Openmode __a) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Openmode + operator~(_Ios_Openmode __a) _GLIBCXX_NOTHROW { return _Ios_Openmode(~static_cast(__a)); } + _GLIBCXX14_CONSTEXPR inline const _Ios_Openmode& - operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) + operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW { return __a = __a | __b; } + _GLIBCXX14_CONSTEXPR inline const _Ios_Openmode& - operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) + operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW { return __a = __a & __b; } + _GLIBCXX14_CONSTEXPR inline const _Ios_Openmode& - operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) + operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW { return __a = __a ^ __b; } @@ -162,32 +176,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _S_ios_iostate_min = ~__INT_MAX__ }; - inline _GLIBCXX_CONSTEXPR _Ios_Iostate - operator&(_Ios_Iostate __a, _Ios_Iostate __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Iostate + operator&(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW { return _Ios_Iostate(static_cast(__a) & static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Iostate - operator|(_Ios_Iostate __a, _Ios_Iostate __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Iostate + operator|(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW { return _Ios_Iostate(static_cast(__a) | static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Iostate - operator^(_Ios_Iostate __a, _Ios_Iostate __b) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Iostate + operator^(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW { return _Ios_Iostate(static_cast(__a) ^ static_cast(__b)); } - inline _GLIBCXX_CONSTEXPR _Ios_Iostate - operator~(_Ios_Iostate __a) + _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR + inline _Ios_Iostate + operator~(_Ios_Iostate __a) _GLIBCXX_NOTHROW { return _Ios_Iostate(~static_cast(__a)); } + _GLIBCXX14_CONSTEXPR inline const _Ios_Iostate& - operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) + operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW { return __a = __a | __b; } + _GLIBCXX14_CONSTEXPR inline const _Ios_Iostate& - operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) + operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW { return __a = __a & __b; } - inline const _Ios_Iostate& - operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) + _GLIBCXX14_CONSTEXPR + inline const _Ios_Iostate& + operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW { return __a = __a ^ __b; } diff --git a/libstdc++-v3/include/bits/regex_constants.h b/libstdc++-v3/include/bits/regex_constants.h index 5e567ec2027..437895f1dc3 100644 --- a/libstdc++-v3/include/bits/regex_constants.h +++ b/libstdc++-v3/include/bits/regex_constants.h @@ -186,44 +186,48 @@ namespace regex_constants */ _GLIBCXX17_INLINE constexpr syntax_option_type __polynomial = _S_polynomial; - constexpr inline syntax_option_type - operator&(syntax_option_type __a, syntax_option_type __b) + [[__nodiscard__]] + constexpr syntax_option_type + operator&(syntax_option_type __a, syntax_option_type __b) noexcept { return (syntax_option_type)(static_cast(__a) & static_cast(__b)); } - constexpr inline syntax_option_type - operator|(syntax_option_type __a, syntax_option_type __b) + [[__nodiscard__]] + constexpr syntax_option_type + operator|(syntax_option_type __a, syntax_option_type __b) noexcept { return (syntax_option_type)(static_cast(__a) | static_cast(__b)); } - constexpr inline syntax_option_type - operator^(syntax_option_type __a, syntax_option_type __b) + [[__nodiscard__]] + constexpr syntax_option_type + operator^(syntax_option_type __a, syntax_option_type __b) noexcept { return (syntax_option_type)(static_cast(__a) ^ static_cast(__b)); } - constexpr inline syntax_option_type - operator~(syntax_option_type __a) + [[__nodiscard__]] + constexpr syntax_option_type + operator~(syntax_option_type __a) noexcept { return (syntax_option_type)(~static_cast(__a)); } _GLIBCXX14_CONSTEXPR inline syntax_option_type& - operator&=(syntax_option_type& __a, syntax_option_type __b) + operator&=(syntax_option_type& __a, syntax_option_type __b) noexcept { return __a = __a & __b; } _GLIBCXX14_CONSTEXPR inline syntax_option_type& - operator|=(syntax_option_type& __a, syntax_option_type __b) + operator|=(syntax_option_type& __a, syntax_option_type __b) noexcept { return __a = __a | __b; } _GLIBCXX14_CONSTEXPR inline syntax_option_type& - operator^=(syntax_option_type& __a, syntax_option_type __b) + operator^=(syntax_option_type& __a, syntax_option_type __b) noexcept { return __a = __a ^ __b; } ///@} @@ -367,44 +371,48 @@ namespace regex_constants */ _GLIBCXX17_INLINE constexpr match_flag_type format_first_only = _S_first_only; - constexpr inline match_flag_type - operator&(match_flag_type __a, match_flag_type __b) + [[__nodiscard__]] + constexpr match_flag_type + operator&(match_flag_type __a, match_flag_type __b) noexcept { return (match_flag_type)(static_cast(__a) & static_cast(__b)); } - constexpr inline match_flag_type - operator|(match_flag_type __a, match_flag_type __b) + [[__nodiscard__]] + constexpr match_flag_type + operator|(match_flag_type __a, match_flag_type __b) noexcept { return (match_flag_type)(static_cast(__a) | static_cast(__b)); } - constexpr inline match_flag_type - operator^(match_flag_type __a, match_flag_type __b) + [[__nodiscard__]] + constexpr match_flag_type + operator^(match_flag_type __a, match_flag_type __b) noexcept { return (match_flag_type)(static_cast(__a) ^ static_cast(__b)); } - constexpr inline match_flag_type - operator~(match_flag_type __a) + [[__nodiscard__]] + constexpr match_flag_type + operator~(match_flag_type __a) noexcept { return (match_flag_type)(~static_cast(__a)); } _GLIBCXX14_CONSTEXPR inline match_flag_type& - operator&=(match_flag_type& __a, match_flag_type __b) + operator&=(match_flag_type& __a, match_flag_type __b) noexcept { return __a = __a & __b; } _GLIBCXX14_CONSTEXPR inline match_flag_type& - operator|=(match_flag_type& __a, match_flag_type __b) + operator|=(match_flag_type& __a, match_flag_type __b) noexcept { return __a = __a | __b; } _GLIBCXX14_CONSTEXPR inline match_flag_type& - operator^=(match_flag_type& __a, match_flag_type __b) + operator^=(match_flag_type& __a, match_flag_type __b) noexcept { return __a = __a ^ __b; } ///@} diff --git a/libstdc++-v3/include/experimental/bits/fs_fwd.h b/libstdc++-v3/include/experimental/bits/fs_fwd.h index a5b8feaaa4a..565f2e43692 100644 --- a/libstdc++-v3/include/experimental/bits/fs_fwd.h +++ b/libstdc++-v3/include/experimental/bits/fs_fwd.h @@ -102,6 +102,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @{ /// @relates copy_options + [[__nodiscard__]] constexpr copy_options operator&(copy_options __x, copy_options __y) noexcept { @@ -110,6 +111,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) & static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr copy_options operator|(copy_options __x, copy_options __y) noexcept { @@ -118,6 +120,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) | static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr copy_options operator^(copy_options __x, copy_options __y) noexcept { @@ -126,6 +129,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr copy_options operator~(copy_options __x) noexcept { @@ -174,6 +178,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @{ /// @relates std::experimental::filesystem::perms + [[__nodiscard__]] constexpr perms operator&(perms __x, perms __y) noexcept { @@ -182,6 +187,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) & static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr perms operator|(perms __x, perms __y) noexcept { @@ -190,6 +196,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) | static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr perms operator^(perms __x, perms __y) noexcept { @@ -198,6 +205,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr perms operator~(perms __x) noexcept { @@ -225,6 +233,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// @{ /// @relates directory_options + [[__nodiscard__]] constexpr directory_options operator&(directory_options __x, directory_options __y) noexcept { @@ -233,6 +242,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) & static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr directory_options operator|(directory_options __x, directory_options __y) noexcept { @@ -241,6 +251,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) | static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr directory_options operator^(directory_options __x, directory_options __y) noexcept { @@ -249,6 +260,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 static_cast<__utype>(__x) ^ static_cast<__utype>(__y)); } + [[__nodiscard__]] constexpr directory_options operator~(directory_options __x) noexcept { diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 21c387973f1..e516e3b2da8 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -622,18 +622,22 @@ namespace __detail scientific = 1, fixed = 2, hex = 4, general = fixed | scientific }; + [[nodiscard]] constexpr chars_format operator|(chars_format __lhs, chars_format __rhs) noexcept { return (chars_format)((unsigned)__lhs | (unsigned)__rhs); } + [[nodiscard]] constexpr chars_format operator&(chars_format __lhs, chars_format __rhs) noexcept { return (chars_format)((unsigned)__lhs & (unsigned)__rhs); } + [[nodiscard]] constexpr chars_format operator^(chars_format __lhs, chars_format __rhs) noexcept { return (chars_format)((unsigned)__lhs ^ (unsigned)__rhs); } + [[nodiscard]] constexpr chars_format operator~(chars_format __fmt) noexcept { return (chars_format)~(unsigned)__fmt; } diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index 1cba04a0e5a..9e75ae98b13 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -152,33 +152,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION deferred = 2 }; + [[__nodiscard__]] constexpr launch operator&(launch __x, launch __y) noexcept { return static_cast( static_cast(__x) & static_cast(__y)); } + [[__nodiscard__]] constexpr launch operator|(launch __x, launch __y) noexcept { return static_cast( static_cast(__x) | static_cast(__y)); } + [[__nodiscard__]] constexpr launch operator^(launch __x, launch __y) noexcept { return static_cast( static_cast(__x) ^ static_cast(__y)); } + [[__nodiscard__]] constexpr launch operator~(launch __x) noexcept { return static_cast(~static_cast(__x)); } + _GLIBCXX14_CONSTEXPR inline launch& operator&=(launch& __x, launch __y) noexcept { return __x = __x & __y; } + _GLIBCXX14_CONSTEXPR inline launch& operator|=(launch& __x, launch __y) noexcept { return __x = __x | __y; } + _GLIBCXX14_CONSTEXPR inline launch& operator^=(launch& __x, launch __y) noexcept { return __x = __x ^ __y; } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/bitmask_types.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/bitmask_types.cc new file mode 100644 index 00000000000..aa3d36e1c45 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/bitmask_types.cc @@ -0,0 +1,56 @@ +// { dg-do compile { target c++17 } } +#include + +namespace fs = std::filesystem; + +void +test_copy_options() +{ + using T = fs::copy_options; + constexpr T val = T::none; + constexpr T all = ((val | val) & val) ^ ~val; + static_assert( noexcept(((val | val) & val) ^ ~val) ); + val & val; // { dg-warning "ignoring return value" } + val | val; // { dg-warning "ignoring return value" } + val ^ val; // { dg-warning "ignoring return value" } + ~val; // { dg-warning "ignoring return value" } +} + +void +test_perms() +{ + using T = fs::perms; + constexpr T val = T::none; + constexpr T all = ((val | val) & val) ^ ~val; + static_assert( noexcept(((val | val) & val) ^ ~val) ); + val & val; // { dg-warning "ignoring return value" } + val | val; // { dg-warning "ignoring return value" } + val ^ val; // { dg-warning "ignoring return value" } + ~val; // { dg-warning "ignoring return value" } +} + +void +test_perm_options() +{ + using T = fs::perm_options; + constexpr T val = T::replace; + constexpr T all = ((val | val) & val) ^ ~val; + static_assert( noexcept(((val | val) & val) ^ ~val) ); + val & val; // { dg-warning "ignoring return value" } + val | val; // { dg-warning "ignoring return value" } + val ^ val; // { dg-warning "ignoring return value" } + ~val; // { dg-warning "ignoring return value" } +} + +void +test_directory_options() +{ + using T = fs::directory_options; + constexpr T val = T::none; + constexpr T all = ((val | val) & val) ^ ~val; + static_assert( noexcept(((val | val) & val) ^ ~val) ); + val & val; // { dg-warning "ignoring return value" } + val | val; // { dg-warning "ignoring return value" } + val ^ val; // { dg-warning "ignoring return value" } + ~val; // { dg-warning "ignoring return value" } +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc index 64ef31d9cd0..604d2aa6b5a 100644 --- a/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc @@ -27,3 +27,7 @@ int main() { __gnu_test::bitmask_operators(); } +// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 } diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc index 218cf8b8a95..a98435867ed 100644 --- a/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc @@ -27,3 +27,7 @@ int main() { __gnu_test::bitmask_operators(); } +// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 } diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc index b5f1e781676..6d024217362 100644 --- a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc @@ -27,3 +27,7 @@ int main() { __gnu_test::bitmask_operators(); } +// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 } +// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 } -- 2.43.0