From 12968577b6539f32b3c8fd597a8bd9e4c7279b6a Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Tue, 5 Nov 2024 10:51:52 +0000 Subject: [PATCH] Add [[nodiscard]] and suppress warnings in unit test file --- include/exiv2/slice.hpp | 8 ++++---- unitTests/test_slice.cpp | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/exiv2/slice.hpp b/include/exiv2/slice.hpp index 98b5e6c5c4..4ed5a528fd 100644 --- a/include/exiv2/slice.hpp +++ b/include/exiv2/slice.hpp @@ -433,7 +433,7 @@ struct Slice : public Internal::MutableSliceBase subSlice(size_t begin, size_t end) const { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) const { return this->to_const_base().template subSlice>(begin, end); } }; @@ -453,7 +453,7 @@ struct Slice : public Internal::ConstSliceBase::type; #endif - Slice subSlice(size_t begin, size_t end) const { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) const { return Internal::ConstSliceBase::template subSlice>(begin, end); } @@ -486,7 +486,7 @@ struct Slice : public Internal::ConstSliceBase subSlice(size_t begin, size_t end) const { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) const { return Internal::ConstSliceBase::template subSlice>(begin, end); } @@ -501,7 +501,7 @@ struct Slice : public Internal::MutableSliceBase subSlice(size_t begin, size_t end) { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) { return Internal::MutableSliceBase::template subSlice>(begin, end); } diff --git a/unitTests/test_slice.cpp b/unitTests/test_slice.cpp index 710bfdb427..32836e93a0 100644 --- a/unitTests/test_slice.cpp +++ b/unitTests/test_slice.cpp @@ -102,9 +102,9 @@ TYPED_TEST_P(slice, subSliceSuccessfulConstruction) { // | | middle auto center_vals = this->getTestSlice(3, 7); ASSERT_EQ(center_vals.size(), static_cast(4)); - ASSERT_NO_THROW(center_vals.subSlice(1, 3)); + ASSERT_NO_THROW((void)center_vals.subSlice(1, 3)); - ASSERT_NO_THROW(center_vals.subSlice(1, center_vals.size())); + ASSERT_NO_THROW((void)center_vals.subSlice(1, center_vals.size())); } TYPED_TEST_P(slice, subSliceFunctions) { @@ -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((void)middle.subSlice(1, 5), std::out_of_range); + ASSERT_THROW((void)middle.subSlice(2, 1), std::out_of_range); + ASSERT_THROW((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::max() - 2, 3), std::out_of_range); - ASSERT_THROW(center_vals.subSlice(2, std::numeric_limits::max() - 1), std::out_of_range); + ASSERT_THROW((void)center_vals.subSlice(std::numeric_limits::max() - 2, 3), std::out_of_range); + ASSERT_THROW((void)center_vals.subSlice(2, std::numeric_limits::max() - 1), std::out_of_range); } /*!