From 83585d4f39f8990c2d8a0dc6cde69e1875fb2f75 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 6 Nov 2026 22:16:43 +0100 Subject: [PATCH] tests: Fix compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [why] We get a warning for the tests with accumulate over floating accumulators because the expected result is given as integer: In file included from ../subprojects/Catch2-3.16.1/src/catch2/internal/catch_assertion_handler.hpp:12, from ../subprojects/Catch2-3.16.1/src/catch2/internal/catch_test_macro_impl.hpp:12, from ../subprojects/Catch2-3.16.1/src/catch2/catch_test_macros.hpp:11, from ../subprojects/Catch2-3.16.1/src/catch2/catch_template_test_macros.hpp:20, from ../tests/test_statistics.cc:35: ../subprojects/Catch2-3.16.1/src/catch2/internal/catch_decomposer.hpp: In instantiation of ‘constexpr std::enable_if_t<((bool)std::conjunction::type&, typename std::remove_reference<_Arg>::type&, void>, Catch::capture_by_value >::value), Catch::BinaryExpr > Catch::operator==(ExprLhs&&, RhsT) [with LhsT = float; RhsT = int; std::enable_if_t<((bool)std::conjunction::type&, typename std::remove_reference<_Arg>::type&, void>, capture_by_value >::value), BinaryExpr > = BinaryExpr; typename std::remove_reference<_Tp>::type = float; typename std::remove_reference<_Arg>::type = int]’: ../tests/test_statistics.cc:481:9: required from ‘void CATCH2_INTERNAL_TEMPLATE_TEST_34() [with TestType = float]’ 482 | [](TestType accu, TestType* el) { return accu + *el; }) == 14); ../tests/test_statistics.cc:457:1: required from ‘void {anonymous}::ns_CATCH2_INTERNAL_TEMPLATE_TEST_35::reg_test(Catch::Detail::TypeList, Catch::NameAndTags) [with Ts = {float}]’ 83 | INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ../tests/test_statistics.cc:457:1: required from ‘{anonymous}::ns_CATCH2_INTERNAL_TEMPLATE_TEST_35::CATCH2_INTERNAL_TEMPLATE_TEST_35::CATCH2_INTERNAL_TEMPLATE_TEST_35() [with Types = {Catch::Detail::TypeList, Catch::Detail::TypeList}]’ 90 | (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \ | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../tests/test_statistics.cc:457:1: required from here 94 | TestName();\ | ^ ../subprojects/Catch2-3.16.1/src/catch2/internal/catch_decomposer.hpp:308:53: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion] 308 | return { static_cast( lhs.getLhs() op rhs ), \ | ^~~ ../subprojects/Catch2-3.16.1/src/catch2/internal/catch_decomposer.hpp:345:5: note: in expansion of macro ‘CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR’ 345 | CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == ) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compiler: gcc 15.2.0 [how] Compare with a variable of the same type as the result (accumulator value). Signed-off-by: Fini Jastrow --- tests/test_statistics.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/test_statistics.cc b/tests/test_statistics.cc index 8730228..f95a562 100644 --- a/tests/test_statistics.cc +++ b/tests/test_statistics.cc @@ -463,10 +463,11 @@ TEMPLATE_TEST_CASE("general accumulate()", "[statistics]", v.push_back(5); v.push_back(3); v.push_back(9); + auto const expectation = TestType{ 18 }; REQUIRE(std::accumulate(v.cbegin(), v.cend(), TestType{ }, - [](TestType a, TestType el) { return a + el; }) == 18); + [](TestType a, TestType el) { return a + el; }) == expectation); REQUIRE(gul17::accumulate(v, - [](TestType a, TestType el) { return a + el; }) == 18); + [](TestType a, TestType el) { return a + el; }) == expectation); } SECTION("pointer accumulate") { auto a = TestType{ 4 }; @@ -478,10 +479,11 @@ TEMPLATE_TEST_CASE("general accumulate()", "[statistics]", v.push_back(&b); v.push_back(&c); v.push_back(&d); + auto const expectation = TestType{ 14 }; REQUIRE(std::accumulate(v.cbegin(), v.cend(), TestType{ }, - [](TestType accu, TestType* el) { return accu + *el; }) == 14); + [](TestType accu, TestType* el) { return accu + *el; }) == expectation); REQUIRE(gul17::accumulate(v, - [](TestType accu, TestType* el) { return accu + *el; }) == 14); + [](TestType accu, TestType* el) { return accu + *el; }) == expectation); } SECTION("user type accumulate") { struct UserType { @@ -495,10 +497,11 @@ TEMPLATE_TEST_CASE("general accumulate()", "[statistics]", v.emplace_back(TestType{ 2 }, true); v.emplace_back(TestType{ 3 }, true); v.emplace_back(TestType{ 7 }, true); + auto const expectation = TestType{ 19 }; REQUIRE(std::accumulate(v.cbegin(), v.cend(), TestType{ }, - [](TestType accu, UserType const& el) { return accu + el.e; }) == 19); + [](TestType accu, UserType const& el) { return accu + el.e; }) == expectation); REQUIRE(gul17::accumulate(v, - [](TestType accu, UserType const& el) { return accu + el.e; }) == 19); + [](TestType accu, UserType const& el) { return accu + el.e; }) == expectation); } }