Skip to content

Commit e7baa25

Browse files
committed
[libc++][expected] Applied [[nodiscard]]
[[nodiscard]] should be applied to functions where discarding the return value is most likely a correctness issue. - https://libcxx.llvm.org/CodingGuidelines.html - https://wg21.link/expected.bad.void - https://wg21.link/expected.bad - https://wg21.link/expected.expected - https://wg21.link/expected.void - https://wg21.link/expected.unexpected
1 parent 38678a9 commit e7baa25

File tree

4 files changed

+277
-72
lines changed

4 files changed

+277
-72
lines changed

libcxx/include/__expected/bad_expected_access.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ class _LIBCPP_EXPORTED_FROM_ABI bad_expected_access<void> : public exception {
4343

4444
public:
4545
# if _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION
46-
const char* what() const noexcept override;
46+
[[nodiscard]] const char* what() const noexcept override;
4747
# else
48-
_LIBCPP_HIDE_FROM_ABI_VIRTUAL const char* what() const noexcept override { return "bad access to std::expected"; }
48+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL const char* what() const noexcept override {
49+
return "bad access to std::expected";
50+
}
4951
# endif
5052
};
5153
_LIBCPP_DIAGNOSTIC_POP
@@ -55,10 +57,10 @@ class bad_expected_access : public bad_expected_access<void> {
5557
public:
5658
_LIBCPP_HIDE_FROM_ABI explicit bad_expected_access(_Err __e) : __unex_(std::move(__e)) {}
5759

58-
_LIBCPP_HIDE_FROM_ABI _Err& error() & noexcept { return __unex_; }
59-
_LIBCPP_HIDE_FROM_ABI const _Err& error() const& noexcept { return __unex_; }
60-
_LIBCPP_HIDE_FROM_ABI _Err&& error() && noexcept { return std::move(__unex_); }
61-
_LIBCPP_HIDE_FROM_ABI const _Err&& error() const&& noexcept { return std::move(__unex_); }
60+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Err& error() & noexcept { return __unex_; }
61+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const _Err& error() const& noexcept { return __unex_; }
62+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Err&& error() && noexcept { return std::move(__unex_); }
63+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const _Err&& error() const&& noexcept { return std::move(__unex_); }
6264

6365
private:
6466
_Err __unex_;

0 commit comments

Comments
 (0)