Skip to content

Commit 4aaada9

Browse files
committed
lib result with fully nodiscard.
Make result expected/unexpected fully nodiscard to prevent ignored return values.
1 parent 0130881 commit 4aaada9

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

score/json/internal/parser/vajson/unit_test/ut_depth_counter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace unit_test
3535
TEST(UT__DepthCounter, MoveAssignment)
3636
{
3737
internal::DepthCounter dc{};
38-
dc.AddArray();
39-
dc.AddValue();
38+
score::cpp::ignore = dc.AddArray();
39+
score::cpp::ignore = dc.AddValue();
4040
auto result = dc.CheckEndOfFile();
4141
ASSERT_EQ(result.error(), JsonErrc::kInvalidJson);
4242
ASSERT_EQ(result.error().UserMessage(),
@@ -62,8 +62,8 @@ TEST(UT__DepthCounter, MoveAssignment)
6262
TEST(UT__DepthCounter, MoveConstruction)
6363
{
6464
internal::DepthCounter dc{};
65-
dc.AddArray();
66-
dc.AddValue();
65+
score::cpp::ignore = dc.AddArray();
66+
score::cpp::ignore = dc.AddValue();
6767

6868
const auto result = dc.CheckEndOfFile();
6969
ASSERT_EQ(result.error(), JsonErrc::kInvalidJson);

score/json/internal/parser/vajson/unit_test/ut_json_ops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ TEST(UT__JsonOps, ReadStringAbortsOnEmpty)
158158
{
159159
TestStream ts{"Does not matter"};
160160

161-
ASSERT_DEATH(ts.ops.ReadString(""), "JsonOps::ReadString: Cannot check for empty string");
161+
ASSERT_DEATH(score::cpp::ignore = ts.ops.ReadString(""), "JsonOps::ReadString: Cannot check for empty string");
162162
}
163163

164164
/*!

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)