libstdc++: Add [[nodiscard]] to std::span members
commita92a434024c59f57dc24328d946f97a5e71cee94
authorJonathan Wakely <jwakely@redhat.com>
Sat, 4 Nov 2023 08:30:54 +0000 (4 08:30 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 11 Nov 2023 00:41:08 +0000 (11 00:41 +0000)
treef624f9ed450fcfec8ada600793b34d0044b00d2c
parent898fd81b831c106859bc99e65c7c1cbb642320c8
libstdc++: Add [[nodiscard]] to std::span members

All std::span member functions are pure functions that have no side
effects. They are only useful for their return value, so they should all
warn if that value is not used.

libstdc++-v3/ChangeLog:

* include/std/span (span, as_bytes, as_writable_bytes): Add
[[nodiscard]] attribute on all non-void functions.
* testsuite/23_containers/span/back_assert_neg.cc: Suppress
nodiscard warning.
* testsuite/23_containers/span/back_neg.cc: Likewise.
* testsuite/23_containers/span/first_2_assert_neg.cc: Likewise.
* testsuite/23_containers/span/first_assert_neg.cc: Likewise.
* testsuite/23_containers/span/first_neg.cc: Likewise.
* testsuite/23_containers/span/front_assert_neg.cc: Likewise.
* testsuite/23_containers/span/front_neg.cc: Likewise.
* testsuite/23_containers/span/index_op_assert_neg.cc: Likewise.
* testsuite/23_containers/span/index_op_neg.cc: Likewise.
* testsuite/23_containers/span/last_2_assert_neg.cc: Likewise.
* testsuite/23_containers/span/last_assert_neg.cc: Likewise.
* testsuite/23_containers/span/last_neg.cc: Likewise.
* testsuite/23_containers/span/subspan_2_assert_neg.cc:
Likewise.
* testsuite/23_containers/span/subspan_3_assert_neg.cc:
Likewise.
* testsuite/23_containers/span/subspan_4_assert_neg.cc:
Likewise.
* testsuite/23_containers/span/subspan_5_assert_neg.cc:
Likewise.
* testsuite/23_containers/span/subspan_6_assert_neg.cc:
Likewise.
* testsuite/23_containers/span/subspan_assert_neg.cc: Likewise.
* testsuite/23_containers/span/subspan_neg.cc: Likewise.
* testsuite/23_containers/span/nodiscard.cc: New test.
21 files changed:
libstdc++-v3/include/std/span
libstdc++-v3/testsuite/23_containers/span/back_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/back_neg.cc
libstdc++-v3/testsuite/23_containers/span/first_2_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/first_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/first_neg.cc
libstdc++-v3/testsuite/23_containers/span/front_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/front_neg.cc
libstdc++-v3/testsuite/23_containers/span/index_op_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/index_op_neg.cc
libstdc++-v3/testsuite/23_containers/span/last_2_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/last_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/last_neg.cc
libstdc++-v3/testsuite/23_containers/span/nodiscard.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/span/subspan_2_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/subspan_3_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/subspan_4_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/subspan_5_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/subspan_6_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/subspan_assert_neg.cc
libstdc++-v3/testsuite/23_containers/span/subspan_neg.cc