From patchwork Tue Feb 27 11:41:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905019 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DQiB+dV6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbLh0gfZz1yX4 for ; Tue, 27 Feb 2024 22:47:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C6273858017 for ; Tue, 27 Feb 2024 11:47:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6A9D53858C31 for ; Tue, 27 Feb 2024 11:45:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A9D53858C31 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 6A9D53858C31 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034336; cv=none; b=g/NgUzTS7TqBQZDH9hoY2+WJ2VxeclO/yCHcJk+zvWNKbW3wWC2tIxxJ4vGVyfdCN3YU5sRHo+kuYOjOy1WnTEStl63HC9HqNPXk9oftVYaYKEPZAcs9jIHuF3xTcIXN7I1avC5Zh0Tvhh2LB/t6rMhBqllUT+G0HpHwvLJjPCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034336; c=relaxed/simple; bh=pu3iJEbKefOmuCXRRfBs5et/K9EgSVg0lUdlmFwblQA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xh+ravPymu5Q92I/r7J86ts0Dj2AqiUlqJvWNsSKSmrYhBt5aAUvq0g20ucC1q0RINYQzN+KE7Q7SQxoA4rTddnobm4IXuOU98zOhJsjOIk1m0egbCUSy8KNVR9qZDHvkLluKL9PVP8bCMlEM1ypwbx6a1BkBCjfXpsU5RSHPto= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034332; 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=FkqA/w7vPfxAQ/u+9QDBPvquWX6k1XFkozOYq6uhwzw=; b=DQiB+dV6yvxWz54bVp9lzeOC9BYJLErQvDW1YR8SZDJSxiuELYVvJ1uNk7XC/ABne92LUR g1SwyRyXEKt4KPKrLC7bHHeLRROQGC/Fip692IcYl2Sanf8eAhrSNb2CI13lkN8b7TBzo3 UXGGv64jbTyWk4i8UgfwslDOkh6515s= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-hJku83AfMm2s2cvl5-Gx7w-1; Tue, 27 Feb 2024 06:45:29 -0500 X-MC-Unique: hJku83AfMm2s2cvl5-Gx7w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 AE14B835148; Tue, 27 Feb 2024 11:45:29 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7ABC12166B33; Tue, 27 Feb 2024 11:45:29 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 1/8] libstdc++: Add more [[nodiscard]] to Date: Tue, 27 Feb 2024 11:41:58 +0000 Message-ID: <20240227114528.1350601-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Reviews invited. -- >8 -- libstdc++-v3/ChangeLog: * include/std/stacktrace: Add nodiscard attribute to all functions without side effects. --- libstdc++-v3/include/std/stacktrace | 36 +++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index f570745fe51..92a69a53d98 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -75,12 +75,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // [stacktrace.entry.obs], observers + [[nodiscard]] constexpr native_handle_type native_handle() const noexcept { return _M_pc; } constexpr explicit operator bool() const noexcept { return _M_pc != -1; } // [stacktrace.entry.query], query + [[nodiscard]] string description() const { @@ -89,6 +91,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __s; } + [[nodiscard]] string source_file() const { @@ -97,6 +100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __s; } + [[nodiscard]] uint_least32_t source_line() const { @@ -106,11 +110,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } // [stacktrace.entry.cmp], comparison + [[nodiscard]] friend constexpr bool operator==(const stacktrace_entry& __x, const stacktrace_entry& __y) noexcept { return __x._M_pc == __y._M_pc; } + [[nodiscard]] friend constexpr strong_ordering operator<=>(const stacktrace_entry& __x, const stacktrace_entry& __y) noexcept @@ -384,36 +390,49 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } // [stacktrace.basic.obs], observers + [[nodiscard]] allocator_type get_allocator() const noexcept { return _M_alloc; } + [[nodiscard]] const_iterator begin() const noexcept { return const_iterator{_M_impl._M_frames}; } + [[nodiscard]] const_iterator end() const noexcept { return begin() + size(); } + [[nodiscard]] const_reverse_iterator rbegin() const noexcept { return std::make_reverse_iterator(end()); } + [[nodiscard]] const_reverse_iterator rend() const noexcept { return std::make_reverse_iterator(begin()); } - const_iterator cbegin() const noexcept { return begin(); } - const_iterator cend() const noexcept { return end(); } - const_reverse_iterator crbegin() const noexcept { return rbegin(); }; - const_reverse_iterator crend() const noexcept { return rend(); }; + [[nodiscard]] const_iterator cbegin() const noexcept { return begin(); } + [[nodiscard]] const_iterator cend() const noexcept { return end(); } + + [[nodiscard]] + const_reverse_iterator + crbegin() const noexcept { return rbegin(); }; + + [[nodiscard]] + const_reverse_iterator + crend() const noexcept { return rend(); }; [[nodiscard]] bool empty() const noexcept { return size() == 0; } - size_type size() const noexcept { return _M_impl._M_size; } + [[nodiscard]] size_type size() const noexcept { return _M_impl._M_size; } + [[nodiscard]] size_type max_size() const noexcept { return _Impl::_S_max_size(_M_impl._M_alloc); } + [[nodiscard]] const_reference operator[](size_type __n) const noexcept { @@ -421,6 +440,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return begin()[__n]; } + [[nodiscard]] const_reference at(size_type __n) const { @@ -431,12 +451,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // [stacktrace.basic.cmp], comparisons template + [[nodiscard]] friend bool operator==(const basic_stacktrace& __x, const basic_stacktrace<_Allocator2>& __y) noexcept { return std::equal(__x.begin(), __x.end(), __y.begin(), __y.end()); } template + [[nodiscard]] friend strong_ordering operator<=>(const basic_stacktrace& __x, const basic_stacktrace<_Allocator2>& __y) noexcept @@ -677,6 +699,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __os; } + [[nodiscard]] inline string to_string(const stacktrace_entry& __f) { @@ -686,6 +709,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[nodiscard]] string to_string(const basic_stacktrace<_Allocator>& __st) { @@ -785,6 +809,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<> struct hash { + [[nodiscard]] size_t operator()(const stacktrace_entry& __f) const noexcept { @@ -796,6 +821,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct hash> { + [[nodiscard]] size_t operator()(const basic_stacktrace<_Allocator>& __st) const noexcept { From patchwork Tue Feb 27 11:41:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OmNAmder; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbKZ49sCz1yX4 for ; Tue, 27 Feb 2024 22:46:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1ED203858025 for ; Tue, 27 Feb 2024 11:46:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 39FF0385840D for ; Tue, 27 Feb 2024 11:45:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 39FF0385840D 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 39FF0385840D 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=1709034337; cv=none; b=uABZOU5P94w7pKkTaEARZ1jBzBJFr4j3n72BOGkpZGnxW+KsEuUA0a8U9dm8Hn7FHzuWsOcdaye0VbYz/BxWwjIkZgrrMfMUw4Gj6ZvhHhTn1YsrZLrFx7p+afmeW8u77sL4kxSgl+9kZBOGKZe0wsxkQG28FfofTT9rNFXH2YA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034337; c=relaxed/simple; bh=CHIys3h9B2NLUNxfZ8eeWpDHxOaUbnJ8dsEN6Yffet4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=O4qlStvOqJ6zmZGYaxbRjibcD/ppQO33q8EJFUl7qR0fHjI1fy5FoMYe4cH4p3/wZeLROWlZXAxOOBhSbUKpW4geaZ05iARCJvS+VU+04iEc//ZmClqzTWPRaXOe8gaOD+Dbq79y75nV4WzBK4rFBsJ8EPkdmGE9GE7uoJy9MoY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034334; 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=x0TX6tg4hnVzKpR6vTT8tZR+k1KzPELF7TQN7bF+ziE=; b=OmNAmderoEpUK+jGW2cB2E0Xi4UP84FuTFrp/cfE741r3BAZl9sPmt4QufbF+aYu/EtQok xXsrh/7CXlEV2d4N4piAzQb2mH8ysAWBW6nHsKfl/ewW/PiRz9cekGC+7mp9044Sf8HanA DomyUsD+QEcDDkDn6zoqaMEdnzT+5Q4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-110-zjqdXkB_MiWvfwVJ_PFr4w-1; Tue, 27 Feb 2024 06:45:30 -0500 X-MC-Unique: zjqdXkB_MiWvfwVJ_PFr4w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 7634410650E2; Tue, 27 Feb 2024 11:45:30 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 440611C060B1; Tue, 27 Feb 2024 11:45:30 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/8] libstdc++: Include in Date: Tue, 27 Feb 2024 11:41:59 +0000 Message-ID: <20240227114528.1350601-2-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Reviews invited. -- >8 -- libstdc++-v3/ChangeLog: * include/bits/alloc_traits.h: Include for __make_move_if_noexcept_iterator. --- libstdc++-v3/include/bits/alloc_traits.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index 5e661e04741..82fc79c7b9f 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -38,6 +38,9 @@ # if _GLIBCXX_HOSTED # include # endif +# if __cpp_exceptions +# include // __make_move_if_noexcept_iterator +# endif #endif namespace std _GLIBCXX_VISIBILITY(default) From patchwork Tue Feb 27 11:42:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=i5dGZq/7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbNL1Ddyz1yX4 for ; Tue, 27 Feb 2024 22:48:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1CB1A3858436 for ; Tue, 27 Feb 2024 11:48:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 30BA73858414 for ; Tue, 27 Feb 2024 11:45:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30BA73858414 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 30BA73858414 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034338; cv=none; b=fd1/wiQLygKDEMDO1hye78rnC62Y75JItQWn6mCeo6Qfr/kjNgG/+Sg/pHUJp/4xmRdkHbvnO7m4vGCnT0lsJtd/uq/K62QyKi74dxCfO+x0QrckrK8q/3lM+rLL6k0Ybr2FBiQ1gSq6Y5RKUCJ3oAan/RRtwqccR7QBut4pTe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034338; c=relaxed/simple; bh=JzHP5UA3x06Stdzmtp8zMJvquCj3DdFNr9UOtjD8y3o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xcq/nu3tlUj5hhoydihI2sr/Rt093nc5NnluPsubuLv3j7r8LlBqH8Gb+/OseZiy7O9JqKK3pLqS1smTIfMCkDDRaVAULcOzCNGPwPW1JybysaI49cqsgaheFmTJVMGvhmFGKtDbP1V+shJ6Xi8F0XDQViNjsCBsHZx0MMJM0bw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034334; 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=49j1RWXwG9fp51t9o/9aCKfK0+cbXPzHmibHitJyzhM=; b=i5dGZq/7kkMXoh8z3Argw/wdJ6fObNWHmn2fuV2flWBN16OLl7MbYEsOGKIKVqz4K02uTy V+EH/6RMSAZIVEZv/bN8WuBLM67HRfRzdAp38CB+3dJGhe6VNC9Bp4tRkpQ1Su5Dk4OlLF Nhkm7m+yDkBEsAK2BW3U5BiSAiDkYbw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-U8HRc_i6OFaJVuHPLHfvfw-1; Tue, 27 Feb 2024 06:45:31 -0500 X-MC-Unique: U8HRc_i6OFaJVuHPLHfvfw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 408DB88B762; Tue, 27 Feb 2024 11:45:31 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B113492BC6; Tue, 27 Feb 2024 11:45:30 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 3/8] libstdc++: Fix std::print for Cygwin Date: Tue, 27 Feb 2024 11:42:00 +0000 Message-ID: <20240227114528.1350601-3-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. I am unable to test this on Cygwin myself. Testing and reviews invited. -- >8 -- Cygwin should use std::fwrite, not WriteConsoleW. And the -lstdc++exp library is only needed when running the tests on *-*-mingw*. libstdc++-v3/ChangeLog: * include/std/ostream (vprint_unicode) [__CYGWIN__]: Use POSIX code path for Cygwin instead of Windows. * include/std/print (vprint_unicode) [__CYGWIN__]: Likewise. * testsuite/27_io/basic_ostream/print/1.cc: Only add -lstdc++exp for *-*-mingw* targets. * testsuite/27_io/print/1.cc: Likewise. --- libstdc++-v3/include/std/ostream | 4 ++-- libstdc++-v3/include/std/print | 2 +- libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc | 2 +- libstdc++-v3/testsuite/27_io/print/1.cc | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index 7d501d67489..a136399ad0b 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -906,7 +906,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void vprint_unicode(ostream& __os, string_view __fmt, format_args __args) { -#ifndef _WIN32 +#if !defined(_WIN32) || defined(__CYGWIN__) // For most targets we don't need to do anything special to write // Unicode to a terminal. std::vprint_nonunicode(__os, __fmt, __args); @@ -923,7 +923,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // If stream refers to a terminal, write a Unicode string to it. if (auto __term = __open_terminal(__os.rdbuf())) { -#ifndef _WIN32 +#if !defined(_WIN32) || defined(__CYGWIN__) // For POSIX, __open_terminal(streambuf*) uses fdopen to open a // new file, so we would need to close it here. This code is not // actually compiled because it's inside an #ifdef _WIN32 group, diff --git a/libstdc++-v3/include/std/print b/libstdc++-v3/include/std/print index 492f333dfa6..d44033469de 100644 --- a/libstdc++-v3/include/std/print +++ b/libstdc++-v3/include/std/print @@ -64,7 +64,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void vprint_unicode(FILE* __stream, string_view __fmt, format_args __args) { -#ifndef _WIN32 +#if !defined(_WIN32) || defined(__CYGWIN__) // For most targets we don't need to do anything special to write // Unicode to a terminal. std::vprint_nonunicode(__stream, __fmt, __args); diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc index b3abc570d1e..71a4daa04c9 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc @@ -1,4 +1,4 @@ -// { dg-options "-lstdc++exp" } +// { dg-additional-options "-lstdc++exp" { target { *-*-mingw* } } } // { dg-do run { target c++23 } } // { dg-require-fileio "" } diff --git a/libstdc++-v3/testsuite/27_io/print/1.cc b/libstdc++-v3/testsuite/27_io/print/1.cc index 3cfdac1bb74..6a294e0454b 100644 --- a/libstdc++-v3/testsuite/27_io/print/1.cc +++ b/libstdc++-v3/testsuite/27_io/print/1.cc @@ -1,4 +1,4 @@ -// { dg-options "-lstdc++exp" } +// { dg-additional-options "-lstdc++exp" { target { *-*-mingw* } } } // { dg-do run { target c++23 } } // { dg-require-fileio "" } From patchwork Tue Feb 27 11:42:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HRiBa0YZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbKq0GjDz1yX4 for ; Tue, 27 Feb 2024 22:46:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14389385840D for ; Tue, 27 Feb 2024 11:46:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C9A263858413 for ; Tue, 27 Feb 2024 11:45:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9A263858413 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 C9A263858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034338; cv=none; b=OFer2XQVvJlxsD75J/P2OBjVqNjt2IT9wKrxjHnFE9P2wIvfRgD1Ckb02cdFXiYlS/CXVd7NiG1OBx0HxddZbipybo/x7NOj6WVOzAQrNX3ZRFmFvAN7mo3usELr23vGo3Oa3S95CVFtWSztDY7bvZZOnMyS1ej79w8757wzA5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034338; c=relaxed/simple; bh=zV0IucB9ylBK1JxbWol7kRf3g6WdtTe64i4tD9xytMg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uE1t9O5lVyFmwDmf7mhJWYJmINa01nYjNvemLA9qWeEvRFeMQlNvM9RMsnLXR/NK86CxpF2oHZHd0jnzGY7Y+BLRThNLHaxW/jvBnAMXU4sGIeU1TDPN0/4J+q6npjWlWJrGHD5rtVIMXYB2osAcgWWABFpdNuD2ShIi+1RC0Mk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034334; 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=5z9kdMFuG0Zcxy8i2riDPwaeUfqe4VV2RY+I8wD39BU=; b=HRiBa0YZRuAKkM7ShJY/0sbOTNcNDtyuVjY03ED7pjh46aOChPh4Hnq/QVKFLZ+zIQ5r1g /6Sbs/hHcuIX2AI7vtHrOQgLuD/BSGxF0QSi4WXjhLo9Yq5X12CP+E/MjY9WledchVdOxb rTFfgcnh7yJ9NBtrvgSLtl/V5bXrExI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-_UJHOeY5PMyJz7sFM_NGUQ-1; Tue, 27 Feb 2024 06:45:32 -0500 X-MC-Unique: _UJHOeY5PMyJz7sFM_NGUQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 13A64185A785; Tue, 27 Feb 2024 11:45:32 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id D16B3C01644; Tue, 27 Feb 2024 11:45:31 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 4/8] libstdc++: Fix error handling in std::print Date: Tue, 27 Feb 2024 11:42:01 +0000 Message-ID: <20240227114528.1350601-4-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Reviews invited. -- >8 -- The standard requires an exception if std::print fails to write to a std::ostream. libstdc++-v3/ChangeLog: * include/std/ostream (vprint_nonunicode): Throw if stream state indicates writing failed. * testsuite/27_io/basic_ostream/print/1.cc: Check for exception. * testsuite/27_io/print/1.cc: Likewise. --- libstdc++-v3/include/std/ostream | 5 +++++ .../testsuite/27_io/basic_ostream/print/1.cc | 17 +++++++++++++++++ libstdc++-v3/testsuite/27_io/print/1.cc | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index a136399ad0b..3740ad6edfa 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -901,6 +901,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __catch(...) { __os._M_setstate(ios_base::badbit); } } + + if (!__os) + __throw_system_error(EIO); } inline void @@ -974,6 +977,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __catch(...) { __os._M_setstate(ios_base::badbit); } } + if (!__os) + __throw_system_error(EIO); #endif // _WIN32 } diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc index 71a4daa04c9..14bfb14d556 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc @@ -103,6 +103,22 @@ test_locale() } } +void +test_errors() +{ +#ifdef __cpp_exceptions + std::stringstream in(std::ios::in); + try + { + std::print(in, "{}", "nope"); + VERIFY(false); + } + catch (const std::system_error&) + { + } +#endif +} + int main() { test_print_ostream(); @@ -111,4 +127,5 @@ int main() test_print_no_padding(); test_vprint_nonunicode(); test_locale(); + test_errors(); } diff --git a/libstdc++-v3/testsuite/27_io/print/1.cc b/libstdc++-v3/testsuite/27_io/print/1.cc index 6a294e0454b..d570f7938be 100644 --- a/libstdc++-v3/testsuite/27_io/print/1.cc +++ b/libstdc++-v3/testsuite/27_io/print/1.cc @@ -74,6 +74,21 @@ test_vprint_nonunicode() // { dg-output "garbage in . garbage out" } } +void +test_errors() +{ +#ifdef __cpp_exceptions + try + { + std::print(stdin, "{}", "nope"); + VERIFY(false); + } + catch (const std::system_error&) + { + } +#endif +} + int main() { test_print_default(); @@ -82,4 +97,5 @@ int main() test_println_file(); test_print_raw(); test_vprint_nonunicode(); + test_errors(); } From patchwork Tue Feb 27 11:42:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=E200sWhD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbMV0L1zz1yX4 for ; Tue, 27 Feb 2024 22:47:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 185F738582B1 for ; Tue, 27 Feb 2024 11:47:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 DFCE8385840F for ; Tue, 27 Feb 2024 11:45:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFCE8385840F 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 DFCE8385840F 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=K8ddOVgcZqvE+q9CJTdBfih3mm5nJXXXBEraIdL5TIZ4Tc2e0fwCCZU1uvnAN3QcuEUES1qbUhJD50agADt9atOv0IwKUq4008PrHgzN7rdyt9BpiVf+lD08pTVrGG7Up5R1nDSt49hdTvf2LBpsF39FGTXqm4aAr4A+ZoBLjE0= 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=tgxK2gxxlsrYaLZQlfZ3pqxqYbtJ/HcoaJ3pbgv6lR5Jqc0FK/Duy+UYYQthPrmEteckT88ZEMgd1aZq7d7Xid5pO6DKid/LzRp21B7aFMrKqrGXtfwRaTpmQTj7mTBAvX9NwNYufmxIyFgCdjJwOXT/CYAjCkopjAB8BMnOc60= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034336; 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=E200sWhDZmxYeVgOyVWrPatnjh5QRj5SIxsYqK8/Kp8zxZqU6UnMuBjbgAb1kqIYmp1cx/ 8P0/t3nZv2Q4xllJTPVgc5D+EFeE/1AWt+k+5AQYwS5z4MQ7h9VD86nGjPra/ZkAhTnH+f 8w8CuAWO++I0IMuTd3Btxj/rUU31ygQ= 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 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 } From patchwork Tue Feb 27 11:42:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905022 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DGtGjmJV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbMV423Dz23qP for ; Tue, 27 Feb 2024 22:47:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55A0B385800D for ; Tue, 27 Feb 2024 11:47:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B69F9385841D for ; Tue, 27 Feb 2024 11:45:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B69F9385841D 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 B69F9385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034339; cv=none; b=jtKNM+4SaX1kfKrtIGwx8xF3mGRSGxSwGkwXBiei0WFcoSzZ6fsXUIgQ/vTGtPn26dcxDnUfGP02ZsLYmh3bzocEOMmXZw5v4O3ho/gCHIhNgfpDY49yMnlQvz8Jj1liR3nRm0cUMaKVLGxqWnMZh2Pqhy3JK+LZ8sG1ewETiwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034339; c=relaxed/simple; bh=C5vJlnmpGUAJnC7Uc1t8GdX0L54eib08CQ4Tj1w7cpU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uerszd3b5BSJjxDRNwBp5LYAgMnJQaMx5tdIhjph4+6ArbTZ0z3S6hWz/HBn7CHAXVLWRfZnFwCsWEiH95lDa3DUA9x7wr/y5XH8rzQorgItnBJs64/+itBvGocARgm54lfcGhjd44zlqbW9itXvCsNV1XNHd65Q7Y88Un2bMDI= 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=4XOU0x8sB993T8dA4cmkWaoY/C/Qb4Zkj/yDaNQhNe8=; b=DGtGjmJVlaNw17HvFFdfrHFhTaXJ3jHFRwIixC47u7OLQ624fAy757x1J9MvVyP+IcDEBr prCtY7HsdPQC+Bbv6s5zuGuqIpl+g4a149MQegDyxegoU0cwWE0UBPVNi8mJiGQnoNk4Ly wkVMU0SsW4ZjG2GA9IKXsx7/Ew4kr14= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-_WJiuBcNMI6OWvb35-9dBg-1; Tue, 27 Feb 2024 06:45:34 -0500 X-MC-Unique: _WJiuBcNMI6OWvb35-9dBg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 C690588B766; 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 922AEC185C0; Tue, 27 Feb 2024 11:45:33 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 6/8] libstdc++: Add more nodiscard uses in Date: Tue, 27 Feb 2024 11:42:03 +0000 Message-ID: <20240227114528.1350601-6-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Reviews invited. -- >8 -- libstdc++-v3/ChangeLog: * include/bits/stl_bvector.h (vector::at): Add nodiscard. * include/bits/stl_vector.h (vector::at): Likewise. (operator==, operator<=>, operator<, operator!=, operator>) (operator<=, operator>=): Add nodiscard. * testsuite/23_containers/vector/nodiscard.cc: New test. --- libstdc++-v3/include/bits/stl_bvector.h | 4 +- libstdc++-v3/include/bits/stl_vector.h | 18 +-- .../23_containers/vector/nodiscard.cc | 153 ++++++++++++++++++ 3 files changed, 164 insertions(+), 11 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/nodiscard.cc diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index aa5644b4a0e..2c8b892b07a 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -1101,7 +1101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } public: - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference at(size_type __n) { @@ -1109,7 +1109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return (*this)[__n]; } - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference at(size_type __n) const { diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 6a9543eefce..a8d387f40a1 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -1172,7 +1172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * is first checked that it is in the range of the vector. The * function throws out_of_range if the check fails. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference at(size_type __n) { @@ -1191,7 +1191,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * is first checked that it is in the range of the vector. The * function throws out_of_range if the check fails. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference at(size_type __n) const { @@ -2042,7 +2042,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * and if corresponding elements compare equal. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return (__x.size() == __y.size() @@ -2061,7 +2061,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * `<` and `>=` etc. */ template - _GLIBCXX20_CONSTEXPR + [[nodiscard]] _GLIBCXX20_CONSTEXPR inline __detail::__synth3way_t<_Tp> operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { @@ -2082,32 +2082,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * See std::lexicographical_compare() for how the determination is made. */ template - inline bool + _GLIBCXX_NODISCARD inline bool operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } /// Based on operator== template - inline bool + _GLIBCXX_NODISCARD inline bool operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template - inline bool + _GLIBCXX_NODISCARD inline bool operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template - inline bool + _GLIBCXX_NODISCARD inline bool operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template - inline bool + _GLIBCXX_NODISCARD inline bool operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x < __y); } #endif // three-way comparison diff --git a/libstdc++-v3/testsuite/23_containers/vector/nodiscard.cc b/libstdc++-v3/testsuite/23_containers/vector/nodiscard.cc new file mode 100644 index 00000000000..3b5480d16d4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/nodiscard.cc @@ -0,0 +1,153 @@ +// { dg-do compile { target c++17 } } + +#include + +void +test_observers(std::vector v) +{ + v.size(); // { dg-warning "ignoring return value" } + v.capacity(); // { dg-warning "ignoring return value" } + v.empty(); // { dg-warning "ignoring return value" } +} + +void +test_element_access(std::vector v) +{ + v.front(); // { dg-warning "ignoring return value" } + v.back(); // { dg-warning "ignoring return value" } + v[1]; // { dg-warning "ignoring return value" } + v.at(1); // { dg-warning "ignoring return value" } + v.data(); // { dg-warning "ignoring return value" } + const auto& cv = v; + cv[1]; // { dg-warning "ignoring return value" } + cv.at(1); // { dg-warning "ignoring return value" } + cv.data(); // { dg-warning "ignoring return value" } +} + +void +test_rel_ops(std::vector v) +{ + v == v; // { dg-warning "ignoring return value" } + v != v; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + v < v; // { dg-warning "ignoring return value" } + v > v; // { dg-warning "ignoring return value" } + v <= v; // { dg-warning "ignoring return value" } + v >= v; // { dg-warning "ignoring return value" } +} + +struct S { }; + +void +test_iterators(std::vector v) +{ + v.begin(); // { dg-warning "ignoring return value" } + v.end(); // { dg-warning "ignoring return value" } + v.rbegin(); // { dg-warning "ignoring return value" } + v.rend(); // { dg-warning "ignoring return value" } + const auto& cv = v; + cv.begin(); // { dg-warning "ignoring return value" } + cv.end(); // { dg-warning "ignoring return value" } + cv.rbegin(); // { dg-warning "ignoring return value" } + cv.rend(); // { dg-warning "ignoring return value" } + + v.cbegin(); // { dg-warning "ignoring return value" } + v.cend(); // { dg-warning "ignoring return value" } + v.crbegin(); // { dg-warning "ignoring return value" } + v.crend(); // { dg-warning "ignoring return value" } + + auto i = v.begin(), j = v.end(); + i == j; // { dg-warning "ignoring return value" } + i != j; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + i < j; // { dg-warning "ignoring return value" } + i > j; // { dg-warning "ignoring return value" } + i <= j; // { dg-warning "ignoring return value" } + i >= j; // { dg-warning "ignoring return value" } + + auto ci = cv.begin(), cj = cv.end(); + ci == cj; // { dg-warning "ignoring return value" } + ci != cj; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + ci < cj; // { dg-warning "ignoring return value" } + ci > cj; // { dg-warning "ignoring return value" } + ci <= cj; // { dg-warning "ignoring return value" } + ci >= cj; // { dg-warning "ignoring return value" } + + ci == j; // { dg-warning "ignoring return value" } + ci != j; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + ci < j; // { dg-warning "ignoring return value" } + ci > j; // { dg-warning "ignoring return value" } + ci <= j; // { dg-warning "ignoring return value" } + ci >= j; // { dg-warning "ignoring return value" } +} + +void +test_observers(std::vector v) +{ + v.size(); // { dg-warning "ignoring return value" } + v.capacity(); // { dg-warning "ignoring return value" } + v.empty(); // { dg-warning "ignoring return value" } +} + +void +test_element_access(std::vector v) +{ + v.front(); // { dg-warning "ignoring return value" } + v.back(); // { dg-warning "ignoring return value" } + v[1]; // { dg-warning "ignoring return value" } + v.at(1); // { dg-warning "ignoring return value" } + const auto& cv = v; + cv[1]; // { dg-warning "ignoring return value" } + cv.at(1); // { dg-warning "ignoring return value" } +} + +void +test_rel_ops(std::vector v) +{ + v == v; // { dg-warning "ignoring return value" } + v != v; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + v < v; // { dg-warning "ignoring return value" } + v > v; // { dg-warning "ignoring return value" } + v <= v; // { dg-warning "ignoring return value" } + v >= v; // { dg-warning "ignoring return value" } +} + +void +test_iterators(std::vector v) +{ + v.begin(); // { dg-warning "ignoring return value" } + v.end(); // { dg-warning "ignoring return value" } + v.rbegin(); // { dg-warning "ignoring return value" } + v.rend(); // { dg-warning "ignoring return value" } + const auto& cv = v; + cv.begin(); // { dg-warning "ignoring return value" } + cv.end(); // { dg-warning "ignoring return value" } + cv.rbegin(); // { dg-warning "ignoring return value" } + cv.rend(); // { dg-warning "ignoring return value" } + + v.cbegin(); // { dg-warning "ignoring return value" } + v.cend(); // { dg-warning "ignoring return value" } + v.crbegin(); // { dg-warning "ignoring return value" } + v.crend(); // { dg-warning "ignoring return value" } + + auto i = v.begin(), j = v.end(); + i == j; // { dg-warning "ignoring return value" } + i != j; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + i < j; // { dg-warning "ignoring return value" } + i > j; // { dg-warning "ignoring return value" } + i <= j; // { dg-warning "ignoring return value" } + i >= j; // { dg-warning "ignoring return value" } + + auto ci = cv.begin(), cj = cv.end(); + ci == cj; // { dg-warning "ignoring return value" } + ci != cj; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + ci < cj; // { dg-warning "ignoring return value" } + ci > cj; // { dg-warning "ignoring return value" } + ci <= cj; // { dg-warning "ignoring return value" } + ci >= cj; // { dg-warning "ignoring return value" } + + ci == j; // { dg-warning "ignoring return value" } + ci != j; // { dg-warning "ignoring return value" "PR c++/114104" { target c++17_down } } + ci < j; // { dg-warning "ignoring return value" } + ci > j; // { dg-warning "ignoring return value" } + ci <= j; // { dg-warning "ignoring return value" } + ci >= j; // { dg-warning "ignoring return value" } +} From patchwork Tue Feb 27 11:42:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AxI541xH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbMG4yVJz1yX4 for ; Tue, 27 Feb 2024 22:47:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9DA53858291 for ; Tue, 27 Feb 2024 11:47:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 615D2385841E for ; Tue, 27 Feb 2024 11:45:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 615D2385841E 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 615D2385841E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034341; cv=none; b=Sa/RSHykSlIO6J9F0td9AHLsdUqnq1iP3mMi12HwpYOi/LvVDDt/Wm3w4Lf7yQiOZvgXuPFZWQddYdA/0wVox8tvGBchkEFNxtco6BLHidBnp66iyKhSgXefwggKOFQ7gDCXQKJh3FRy8S76we2o85VkGOfMGVJHim+cojWha8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034341; c=relaxed/simple; bh=/Y32eu9NdBxLbB6jwudOjEL4ES4M9wzNEspA6m+7yNU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fq+8EV1colAwFA5eF4TIuPPT6rinmE/akDp+oyrGT0TmYUaOzanl7VfGjp6cHVcsITIjEpTp4pYS5/jNPxlAcazvFf83O04tBHl6xYznVB/jcTGd2aDoumRJqJ7hUoA2uKYeCE2sEfxQOmZeNOzZUk0hrDMWHxXlPSoaurV8tEI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034337; 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=piRbMQe/OGFCpKa+HooX3TUTL6KHNVCHASgp/mvA10o=; b=AxI541xHNJeQAzSe4Q4jSf7leCCB+jgctRkqk++uNyBklsYMo2xiIN6IH7+xTWWCCERDuT sDB/m3vi8KFVpTxQ029F2r4Abgn2ogjQ8xBnrAjw7EfoZ+ZeS/dg9/jN8DrodJfJhA0GoQ RlgF6IeGHDkRKMgfigcPuLinyQw2qPk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-OflJuzEyNm2N7ZVMX9AXLg-1; Tue, 27 Feb 2024 06:45:34 -0500 X-MC-Unique: OflJuzEyNm2N7ZVMX9AXLg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 A667E835150; Tue, 27 Feb 2024 11:45:34 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7439D112132A; Tue, 27 Feb 2024 11:45:34 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 7/8] libstdc++: Add nodiscard in Date: Tue, 27 Feb 2024 11:42:04 +0000 Message-ID: <20240227114528.1350601-7-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Reviews invited. -- >8 -- libstdc++-v3/ChangeLog: * include/bits/stl_algo.h: * testsuite/25_algorithms/unique/1.cc: Add dg-warning. * testsuite/25_algorithms/unique/11480.cc: Likewise. * testsuite/25_algorithms/unique_copy/26133.cc: Likewise. --- libstdc++-v3/include/bits/stl_algo.h | 38 +++++++++---------- .../testsuite/25_algorithms/unique/1.cc | 1 + .../testsuite/25_algorithms/unique/11480.cc | 2 +- .../25_algorithms/unique_copy/26133.cc | 2 + 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 7a0cf6b6737..bbc130d3e71 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -320,7 +320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * [__first1,__last1-(__last2-__first2)) */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -370,7 +370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, @@ -405,7 +405,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @p [__first,__last), and false otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { return __last == std::find_if_not(__first, __last, __pred); } @@ -423,7 +423,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @p [__first,__last), and false otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); } @@ -442,7 +442,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { return !std::none_of(__first, __last, __pred); } @@ -458,7 +458,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * such that @p __pred(*i) is false, or @p __last if no such iterator exists. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) @@ -483,7 +483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * do not. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) @@ -505,7 +505,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * and @p none_of(mid, __last, __pred) are both true. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _ForwardIterator partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) @@ -572,7 +572,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are copied is unchanged. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _OutputIterator remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value) @@ -606,7 +606,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _OutputIterator remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) @@ -783,7 +783,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) @@ -817,7 +817,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) @@ -886,7 +886,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last) { @@ -917,7 +917,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __binary_pred) @@ -4019,7 +4019,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * for which @c *i == @p __value */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline typename iterator_traits<_InputIterator>::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp& __value) { @@ -4043,7 +4043,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * for which @p __pred(*i) is true. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline typename iterator_traits<_InputIterator>::difference_type count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -4118,7 +4118,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * equal to @p __val. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Integer __count, const _Tp& __val) @@ -4407,7 +4407,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO // DR 538. 241 again: Does unique_copy() require CopyConstructible and // Assignable? template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _OutputIterator unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) @@ -4448,7 +4448,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO // DR 241. Does unique_copy() require CopyConstructible and Assignable? template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _OutputIterator unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, diff --git a/libstdc++-v3/testsuite/25_algorithms/unique/1.cc b/libstdc++-v3/testsuite/25_algorithms/unique/1.cc index 6826e26fdc0..698c370e229 100644 --- a/libstdc++-v3/testsuite/25_algorithms/unique/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/unique/1.cc @@ -27,5 +27,6 @@ int main() using namespace std; list menge; unique (menge.begin(), menge.end()); + // { dg-warning "ignoring return value" "" { target c++17 } 29 } return 0; } diff --git a/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc b/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc index 9d1bd4efe32..a008fc57f54 100644 --- a/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc +++ b/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc @@ -31,7 +31,7 @@ bool compare(int a, int b) // libstdc++/11480 void test01() { - std::unique(a, a+10, compare); + std::unique(a, a+10, compare); // { dg-warning "ignoring return value" "" { target c++17 } } VERIFY( compare_count == 9 ); } diff --git a/libstdc++-v3/testsuite/25_algorithms/unique_copy/26133.cc b/libstdc++-v3/testsuite/25_algorithms/unique_copy/26133.cc index 9f9a26e0dd4..482a610f53c 100644 --- a/libstdc++-v3/testsuite/25_algorithms/unique_copy/26133.cc +++ b/libstdc++-v3/testsuite/25_algorithms/unique_copy/26133.cc @@ -35,10 +35,12 @@ void test01() no_assign in[4]; std::unique_copy(in, in + 4, std::ostream_iterator(oss1, "\n")); + // { dg-warning "ignoring return value" "" { target c++17 } 37 } VERIFY( oss1.str() == "23\n" ); std::unique_copy(in, in + 4, std::ostream_iterator(oss2, "\n"), std::equal_to()); + // { dg-warning "ignoring return value" "" { target c++17 } 41 } VERIFY( oss2.str() == "23\n" ); } From patchwork Tue Feb 27 11:42:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1905025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O5RsL5X7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkbQZ3LkPz23qN for ; Tue, 27 Feb 2024 22:50:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62054385840B for ; Tue, 27 Feb 2024 11:50:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 EBE6A3858292 for ; Tue, 27 Feb 2024 11:45:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBE6A3858292 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 EBE6A3858292 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=1709034342; cv=none; b=JIp9rlp6dAxv6ggIBel4wSuymOGDJA9L8rrAFiZzKvE3KLl6ffEgGzYdTv1DybdR/IVqRWCYr8w3JGSli9gDa+rLFafigL43XUC7WvvB5Kk5KkGQXJr64yI9dKE0pp9MP3iGDxs0OPvSAkjK8bEQbMwBKzsTpt/h76fwMDuGr7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034342; c=relaxed/simple; bh=nI+hQJIGoxfPmppy51RRDZqSU5rNq3wpxDFYUEXidVY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tJKubrup/qx7WLfnbwQM1nb+JGtysDtag07G4p5RPjDPgCFJlnl1h9/xXUaRP7zzxrZyF/ovZuJhPfAv+unRdfLw0/ujYY22ns7XsbGWrUFc0DVJqCBNUDqQcoXekPl+uILroJavGYeSeDykht3O9nad8FAfbYCNT5jOp51nJX8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034338; 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=KpZ/mnAwGB0Zt+fNe62/bM2BnZxfEbHV8c/tiTBzONA=; b=O5RsL5X70EGM05u9+nJaEMXGtRq8lG/QewBQrpjJtDqWwmZDIxc2kt7NC8GkFasiIVEG9b EaDGvZ+XIAuD1SflplsYBV/Yf4CKXzTBd2q93trK3qF5/jbeDh9zJc2yuRpm62DFcQhMZu tSRVmXv1Bc4MQI9VTLOE8btGNYgl7BI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-ZUDFVj85NwuOgrGPWtLHRg-1; Tue, 27 Feb 2024 06:45:35 -0500 X-MC-Unique: ZUDFVj85NwuOgrGPWtLHRg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 6F88388B760; Tue, 27 Feb 2024 11:45:35 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DB0E40C122C; Tue, 27 Feb 2024 11:45:35 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 8/8] libstdc++: Do not define lock-free atomic aliases if not fully lock-free [PR114103] Date: Tue, 27 Feb 2024 11:42:05 +0000 Message-ID: <20240227114528.1350601-8-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. I think we should make this change, because otherwise we define the typedefs for platforms with no lock-free atomics, like hppa-hpux. Instead of lying, those typedefs should be absent on that target. -- >8 -- libstdc++-v3/ChangeLog: PR libstdc++/114103 * include/bits/version.def (atomic_lock_free_type_aliases): Add extra_cond to check for at least one always-lock-free type. * include/bits/version.h: Regenerate. * include/std/atomic (atomic_signed_lock_free) (atomic_unsigned_lock_free): Only use always-lock-free types. --- libstdc++-v3/include/bits/version.def | 1 + libstdc++-v3/include/bits/version.h | 2 +- libstdc++-v3/include/std/atomic | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 502961eb269..d298420121b 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -739,6 +739,7 @@ ftms = { values = { v = 201907; cxxmin = 20; + extra_cond = "(__GCC_ATOMIC_INT_LOCK_FREE | __GCC_ATOMIC_LONG_LOCK_FREE | __GCC_ATOMIC_CHAR_LOCK_FREE) & 2"; }; }; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 7a6fbd35e2e..9107b45a484 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -819,7 +819,7 @@ #undef __glibcxx_want_atomic_float #if !defined(__cpp_lib_atomic_lock_free_type_aliases) -# if (__cplusplus >= 202002L) +# if (__cplusplus >= 202002L) && ((__GCC_ATOMIC_INT_LOCK_FREE | __GCC_ATOMIC_LONG_LOCK_FREE | __GCC_ATOMIC_CHAR_LOCK_FREE) & 2) # define __glibcxx_atomic_lock_free_type_aliases 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_lock_free_type_aliases) # define __cpp_lib_atomic_lock_free_type_aliases 201907L diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index 559f8370459..1462cf5ec23 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -1774,13 +1774,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = atomic>; using atomic_unsigned_lock_free = atomic>; -# elif ATOMIC_INT_LOCK_FREE || !(ATOMIC_LONG_LOCK_FREE || ATOMIC_CHAR_LOCK_FREE) +# elif ATOMIC_INT_LOCK_FREE == 2 using atomic_signed_lock_free = atomic; using atomic_unsigned_lock_free = atomic; -# elif ATOMIC_LONG_LOCK_FREE +# elif ATOMIC_LONG_LOCK_FREE == 2 using atomic_signed_lock_free = atomic; using atomic_unsigned_lock_free = atomic; -# elif ATOMIC_CHAR_LOCK_FREE +# elif ATOMIC_CHAR_LOCK_FREE == 2 using atomic_signed_lock_free = atomic; using atomic_unsigned_lock_free = atomic; # else