From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C96B03858C78 for ; Tue, 27 Feb 2024 11:45:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C96B03858C78 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 C96B03858C78 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=eXyYMmjdozCqMnSur6i4F4KV9pnljlXHvvqyazgWEHqbUYuEkQFCn+X5glI7W7yid7WaghyN++4PTpcO9p2c3IY4Si2vgV8UNSUAWYdGjlCdL5x4uVvPfph4xEX79tflC2sI8IA0zwOy8pjn2Bj0GFDuMSU7e753x5xLmPLFw3Y= 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=bojqeLPC0xo5ARJdWWAc3cSIXADnLh0o33BaIT4WPoRC1a/eodRxkn+bCoZPtNstZJnbrePI9hmX6MuAELC7y8ktpiVgUWIgspGNQDqMzPTHgsPQxZLXcn1QOlnhyfglL/I3/kuWjNxllEi4hRVFZCORMsaXjPFPT/nr6VptYIo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709034331; 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=g57TlFaeX8L98DLSNknTz9XUVaR1kNUfiIvJrFjlepf0bxAngU+DEWIfod2+XYkC3VAozT jDMk8ptkRoUXNS9nINFY7l8wSCBU7BHp42YVDJayUFXs+qPU+ietYJo1B4c7fUvc3Ui9Td /LSLXnfHKiSsoUctHDEJLNm6rV6wvlw= 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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 List-Id: 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 { -- 2.43.0