Skip to content

Commit e8112e8

Browse files
committed
lib result with fully nodiscard.
Make result expected/unexpected fully nodiscard to prevent ignored return values.
1 parent 490dd84 commit e8112e8

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

.github/workflows/restricted_paths.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ jobs:
4747
- 'score/network/**'
4848
- 'score/os/**'
4949
- 'score/quality/compiler_warnings/**'
50+
- 'score/scope_exit/**'
5051
- 'score/static_reflection_with_serialization/**'
5152
- 'score/string_manipulation/**'
53+
- 'score/utils/**'
5254
- name: Block PR if restricted files are changed
5355
if: steps.filter.outputs.restricted == 'true' && github.event_name != 'merge_group'
5456
env:

score/result/details/expected/expected.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ template <typename E>
7676
// copy assignment operators.
7777
// NOLINTBEGIN(cppcoreguidelines-special-member-functions): shall be implicitly declared as per the C++23 standard.
7878
// coverity[autosar_cpp14_a12_0_1_violation]
79-
class unexpected : impl::base_unexpected
79+
class [[nodiscard]] unexpected : impl::base_unexpected
8080
// NOLINTEND(cppcoreguidelines-special-member-functions): shall be implicitly declared as per the C++23 standard.
8181
{
8282
public:
@@ -115,24 +115,24 @@ class unexpected : impl::base_unexpected
115115
// NOLINTNEXTLINE(performance-noexcept-move-constructor) qualification from the move assignment operator of E.
116116
constexpr unexpected& operator=(unexpected&&) = default;
117117

118-
constexpr const E& error() const& noexcept
118+
[[nodiscard]] constexpr const E& error() const& noexcept
119119
{
120120
return value_;
121121
}
122-
constexpr E& error() & noexcept
122+
[[nodiscard]] constexpr E& error() & noexcept
123123
{
124124
// coverity[autosar_cpp14_a9_3_1_violation] by design
125125
return value_;
126126
}
127-
constexpr const E&& error() const&& noexcept
127+
[[nodiscard]] constexpr const E&& error() const&& noexcept
128128
{
129129
// Suppress AUTOSAR C++14 A18-9-3" rule violations. The rule states "The std::move shall not be used on objects
130130
// declared const or const&." the move operation on a const object does not cause unintended behavior it ensures
131131
// a proper copy/move of underlying values.
132132
// coverity[autosar_cpp14_a18_9_3_violation]
133133
return std::move(value_);
134134
}
135-
constexpr E&& error() && noexcept
135+
[[nodiscard]] constexpr E&& error() && noexcept
136136
{
137137
return std::move(value_);
138138
}
@@ -208,7 +208,7 @@ unexpected(E) -> unexpected<E>;
208208
#endif
209209

210210
template <typename T, typename E>
211-
class SPP_EXPECTED_NODISCARD expected : impl::base_expected
211+
class [[nodiscard]] expected : impl::base_expected
212212
{
213213
// Suppress "AUTOSAR C++14 A5-1-7" rule finding. This rule states: "A lambda shall not be an operand to decltype or
214214
// typeid". False-positive, at this point "decltype" is not used with lambda.
@@ -1031,7 +1031,7 @@ class SPP_EXPECTED_NODISCARD expected : impl::base_expected
10311031
};
10321032

10331033
template <typename E>
1034-
class SPP_EXPECTED_NODISCARD expected<void, E> : impl::base_expected
1034+
class [[nodiscard]] expected<void, E> : impl::base_expected
10351035
{
10361036
// Suppress "AUTOSAR C++14 A5-1-7" rule finding. This rule states: "A lambda shall not be an operand to decltype or
10371037
// typeid". False-positive, at this point "decltype" is not used with lambda.

0 commit comments

Comments
 (0)