From 77d00274b4e729ba5eac3cda390d6aa9478567ca Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 30 Jan 2024 10:11:10 +1100 Subject: Avoid warnings in unit tests with const, nullptr, [[nodiscard]], initialisation, and unnamed namespace. --- test/unit/testSparseVector.cxx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test/unit/testSparseVector.cxx') diff --git a/test/unit/testSparseVector.cxx b/test/unit/testSparseVector.cxx index 3a9ac3123..157acfc2d 100644 --- a/test/unit/testSparseVector.cxx +++ b/test/unit/testSparseVector.cxx @@ -39,13 +39,13 @@ TEST_CASE("CompileCopying SparseVector") { SparseVector s2; // Copy constructor - SparseVector sa(s); + const SparseVector sa(s); // Copy assignment SparseVector sb; sb = s; // Move constructor - SparseVector sc(std::move(s)); + const SparseVector sc(std::move(s)); // Move assignment SparseVector sd; sd = (std::move(s2)); @@ -64,7 +64,7 @@ TEST_CASE("CompileCopying SparseVector") { #endif // Move constructor - SparseVector sc(std::move(s)); + const SparseVector sc(std::move(s)); // Move assignment SparseVector s2; SparseVector sd; @@ -73,9 +73,11 @@ TEST_CASE("CompileCopying SparseVector") { } +namespace { + // Helper to produce a string representation of a SparseVector // to simplify checks. -static std::string Representation(const SparseVector &st) { +std::string Representation(const SparseVector &st) { std::string ret; for (int i = 0;i <= st.Length();i++) { const char *value = st.ValueAt(i).get(); @@ -87,6 +89,8 @@ static std::string Representation(const SparseVector &st) { return ret; } +} + TEST_CASE("SparseVector") { SparseVector st; @@ -473,7 +477,7 @@ TEST_CASE("SparseTextString") { SECTION("SetAndMoveString") { st.InsertSpace(0, 2); REQUIRE(2u == st.Length()); - std::string s24("24"); + const std::string s24("24"); st.SetValueAt(0, s24); REQUIRE("24" == s24); // Not moved from REQUIRE("" == st.ValueAt(-1)); -- cgit v1.2.3