Skip to content

Commit

Permalink
Add [[nodiscard]] and suppress warnings in unit test file
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse authored and neheb committed Nov 8, 2024
1 parent 12e33ac commit e13c982
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions include/exiv2/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ struct Slice : public Internal::MutableSliceBase<Internal::ContainerStorage, con
* Constructs a new constant subSlice. Behaves otherwise exactly like
* the non-const version.
*/
Slice<const container> subSlice(size_t begin, size_t end) const {
[[nodiscard]] Slice<const container> subSlice(size_t begin, size_t end) const {
return this->to_const_base().template subSlice<Slice<const container>>(begin, end);
}
};
Expand All @@ -453,7 +453,7 @@ struct Slice<const container> : public Internal::ConstSliceBase<Internal::Contai
using value_type = typename std::remove_cv<typename container::value_type>::type;
#endif

Slice subSlice(size_t begin, size_t end) const {
[[nodiscard]] Slice subSlice(size_t begin, size_t end) const {
return Internal::ConstSliceBase<Internal::ContainerStorage,
const container>::template subSlice<Slice<const container>>(begin, end);
}
Expand Down Expand Up @@ -486,7 +486,7 @@ struct Slice<const T*> : public Internal::ConstSliceBase<Internal::PtrSliceStora
// TODO: use using in C++11
}

Slice<const T*> subSlice(size_t begin, size_t end) const {
[[nodiscard]] Slice<const T*> subSlice(size_t begin, size_t end) const {
return Internal::ConstSliceBase<Internal::PtrSliceStorage, const T*>::template subSlice<Slice<const T*>>(begin,
end);
}
Expand All @@ -501,7 +501,7 @@ struct Slice<T*> : public Internal::MutableSliceBase<Internal::PtrSliceStorage,
// TODO: use using in C++11
}

Slice<T*> subSlice(size_t begin, size_t end) {
[[nodiscard]] Slice<T*> subSlice(size_t begin, size_t end) {
return Internal::MutableSliceBase<Internal::PtrSliceStorage, T*>::template subSlice<Slice<T*>>(begin, end);
}

Expand Down
14 changes: 7 additions & 7 deletions unitTests/test_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ TYPED_TEST_P(slice, subSliceSuccessfulConstruction) {
// | | middle
auto center_vals = this->getTestSlice(3, 7);
ASSERT_EQ(center_vals.size(), static_cast<size_t>(4));
ASSERT_NO_THROW(center_vals.subSlice(1, 3));
ASSERT_NO_THROW(static_cast<void>(center_vals.subSlice(1, 3)));

ASSERT_NO_THROW(center_vals.subSlice(1, center_vals.size()));
ASSERT_NO_THROW(static_cast<void>(center_vals.subSlice(1, center_vals.size())));
}

TYPED_TEST_P(slice, subSliceFunctions) {
Expand All @@ -119,17 +119,17 @@ TYPED_TEST_P(slice, subSliceFailedConstruction) {
// | | middle
auto middle = this->getTestSlice(4, 6);

ASSERT_THROW(middle.subSlice(1, 5), std::out_of_range);
ASSERT_THROW(middle.subSlice(2, 1), std::out_of_range);
ASSERT_THROW(middle.subSlice(2, 2), std::out_of_range);
ASSERT_THROW(static_cast<void>(middle.subSlice(1, 5)), std::out_of_range);
ASSERT_THROW(static_cast<void>(middle.subSlice(2, 1)), std::out_of_range);
ASSERT_THROW(static_cast<void>(middle.subSlice(2, 2)), std::out_of_range);
}

/*! try to cause integer overflows in a sub-optimal implementation */
TYPED_TEST_P(slice, subSliceConstructionOverflowResistance) {
auto center_vals = this->getTestSlice(3, 7);

ASSERT_THROW(center_vals.subSlice(std::numeric_limits<size_t>::max() - 2, 3), std::out_of_range);
ASSERT_THROW(center_vals.subSlice(2, std::numeric_limits<size_t>::max() - 1), std::out_of_range);
ASSERT_THROW(static_cast<void>(center_vals.subSlice(std::numeric_limits<size_t>::max() - 2, 3)), std::out_of_range);
ASSERT_THROW(static_cast<void>(center_vals.subSlice(2, std::numeric_limits<size_t>::max() - 1)), std::out_of_range);
}

/*!
Expand Down

0 comments on commit e13c982

Please sign in to comment.