Skip to content

Fix compiler warnings after Catch2 upgrade - #63

Merged
Finii merged 1 commit into
mainfrom
cleanup/compiler-warnings
Nov 9, 2026
Merged

Finii merged 1 commit into
mainfrom
cleanup/compiler-warnings

Conversation

@Finii

@Finii Finii commented Nov 6, 2026

Copy link
Copy Markdown
Member
[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<Catch::Detail::is_eq_comparable_impl<typename std::remove_reference<_Tp>::type&, typename std::remove_reference<_Arg>::type&, void>, Catch::capture_by_value<RhsT> >::value), Catch::BinaryExpr<LhsT, RhsT> > Catch::operator==(ExprLhs<LhsT>&&, RhsT) [with LhsT = float; RhsT = int; std::enable_if_t<((bool)std::conjunction<Detail::is_eq_comparable_impl<typename std::remove_reference<_Tp>::type&, typename std::remove_reference<_Arg>::type&, void>, capture_by_value<RhsT> >::value), BinaryExpr<LhsT, RhsT> > = BinaryExpr<float, int>; 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<Ts ...>, 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<Types>::CATCH2_INTERNAL_TEMPLATE_TEST_35() [with Types = {Catch::Detail::TypeList<int>, Catch::Detail::TypeList<float>}]’
   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<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
      |                                                                              ^
../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<bool>( 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).

@Finii
Finii requested a review from alt-graph November 6, 2026 21:22
@Finii Finii added the cleanup label Nov 6, 2026

@alt-graph alt-graph left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Finii! We could add a const, but I can't think of any better comments. ;-)

[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<Catch::Detail::is_eq_comparable_impl<typename std::remove_reference<_Tp>::type&, typename std::remove_reference<_Arg>::type&, void>, Catch::capture_by_value<RhsT> >::value), Catch::BinaryExpr<LhsT, RhsT> > Catch::operator==(ExprLhs<LhsT>&&, RhsT) [with LhsT = float; RhsT = int; std::enable_if_t<((bool)std::conjunction<Detail::is_eq_comparable_impl<typename std::remove_reference<_Tp>::type&, typename std::remove_reference<_Arg>::type&, void>, capture_by_value<RhsT> >::value), BinaryExpr<LhsT, RhsT> > = BinaryExpr<float, int>; 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<Ts ...>, 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<Types>::CATCH2_INTERNAL_TEMPLATE_TEST_35() [with Types = {Catch::Detail::TypeList<int>, Catch::Detail::TypeList<float>}]’
   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<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
      |                                                                              ^
../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<bool>( 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 <ulf.fini.jastrow@desy.de>
@Finii
Finii force-pushed the cleanup/compiler-warnings branch from c3e82aa to 83585d4 Compare November 9, 2026 11:48
@Finii

Finii commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Thank you.
East const added 🙃

@Finii
Finii merged commit 5d4cf93 into main Nov 9, 2026
7 checks passed
@Finii
Finii deleted the cleanup/compiler-warnings branch November 9, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants