From ba37e7eb3c51eeb669f14501edecf54f16fb8549 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 1 May 2025 10:40:13 -0700 Subject: [PATCH] [wpimath] Fix warning false positive from GCC 15 (#7948) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` In file included from /usr/include/c++/15.1.1/functional:61, from /home/tav/frc/wpilib/allwpilib/thirdparty/googletest/include/gtest/gtest-matchers.h:43, from /home/tav/frc/wpilib/allwpilib/thirdparty/googletest/include/gtest/internal/gtest-death-test-internal.h:47, from /home/tav/frc/wpilib/allwpilib/thirdparty/googletest/include/gtest/gtest-death-test.h:43, from /home/tav/frc/wpilib/allwpilib/thirdparty/googletest/include/gtest/gtest.h:65, from /home/tav/frc/wpilib/allwpilib/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp:7: In copy constructor ‘std::function<_Res(_ArgTypes ...)>::function(const std::function<_Res(_ArgTypes ...)>&) [with _Res = Eigen::Matrix; _ArgTypes = {const Eigen::Matrix&, const Eigen::Matrix&}]’, inlined from ‘frc::ControlAffinePlantInversionFeedforward::ControlAffinePlantInversionFeedforward(std::function(const Eigen::Matrix&, const Eigen::Matrix&)>, units::time::second_t) [with int States = 2; int Inputs = 1]’ at /home/tav/frc/wpilib/allwpilib/wpimath/src/main/native/include/frc/controller/ControlAffinePlantInversionFeedforward.h:59:19, inlined from ‘virtual void frc::ControlAffinePlantInversionFeedforwardTest_Calculate_Test::TestBody()’ at /home/tav/frc/wpilib/allwpilib/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp:29:70: /usr/include/c++/15.1.1/bits/std_function.h:393:17: error: ‘’ may be used uninitialized [-Werror=maybe-uninitialized] 393 | __x._M_manager(_M_functor, __x._M_functor, __clone_functor); | ~~~~^~~~~~~~~~ /usr/include/c++/15.1.1/bits/std_function.h: In member function ‘virtual void frc::ControlAffinePlantInversionFeedforwardTest_Calculate_Test::TestBody()’: /usr/include/c++/15.1.1/bits/std_function.h:269:7: note: by argument 2 of type ‘const std::_Any_data&’ to ‘static bool std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [with _Res = Eigen::Matrix; _Functor = frc::ControlAffinePlantInversionFeedforwardTest_Calculate_Test::TestBody()::; _ArgTypes = {const Eigen::Matrix&, const Eigen::Matrix&}]’ declared here 269 | _M_manager(_Any_data& __dest, const _Any_data& __source, | ^~~~~~~~~~ /home/tav/frc/wpilib/allwpilib/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp:29:70: note: ‘’ declared here 29 | 20_ms}; | ^ In copy constructor ‘std::function<_Res(_ArgTypes ...)>::function(const std::function<_Res(_ArgTypes ...)>&) [with _Res = Eigen::Matrix; _ArgTypes = {const Eigen::Matrix&}]’, inlined from ‘frc::ControlAffinePlantInversionFeedforward::ControlAffinePlantInversionFeedforward(std::function(const Eigen::Matrix&)>, frc::Matrixd&, units::time::second_t) [with int States = 2; int Inputs = 1]’ at /home/tav/frc/wpilib/allwpilib/wpimath/src/main/native/include/frc/controller/ControlAffinePlantInversionFeedforward.h:79:11, inlined from ‘virtual void frc::ControlAffinePlantInversionFeedforwardTest_CalculateState_Test::TestBody()’ at /home/tav/frc/wpilib/allwpilib/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp:45:73: /usr/include/c++/15.1.1/bits/std_function.h:393:17: error: ‘’ may be used uninitialized [-Werror=maybe-uninitialized] 393 | __x._M_manager(_M_functor, __x._M_functor, __clone_functor); | ~~~~^~~~~~~~~~ /usr/include/c++/15.1.1/bits/std_function.h: In member function ‘virtual void frc::ControlAffinePlantInversionFeedforwardTest_CalculateState_Test::TestBody()’: /usr/include/c++/15.1.1/bits/std_function.h:269:7: note: by argument 2 of type ‘const std::_Any_data&’ to ‘static bool std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [with _Res = Eigen::Matrix; _Functor = frc::ControlAffinePlantInversionFeedforwardTest_CalculateState_Test::TestBody()::; _ArgTypes = {const Eigen::Matrix&}]’ declared here 269 | _M_manager(_Any_data& __dest, const _Any_data& __source, | ^~~~~~~~~~ /home/tav/frc/wpilib/allwpilib/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp:45:73: note: ‘’ declared here 45 | B, 20_ms}; | ^ ``` --- ...ntrolAffinePlantInversionFeedforwardTest.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp b/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp index 5c8e3f15fa..e05720455d 100644 --- a/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp +++ b/wpimath/src/test/native/cpp/controller/ControlAffinePlantInversionFeedforwardTest.cpp @@ -2,8 +2,6 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include - #include #include "frc/EigenCore.h" @@ -22,10 +20,7 @@ Vectord<2> StateDynamics(const Vectord<2>& x) { } TEST(ControlAffinePlantInversionFeedforwardTest, Calculate) { - std::function(const Vectord<2>&, const Vectord<1>&)> - modelDynamics = [](auto& x, auto& u) { return Dynamics(x, u); }; - - frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{modelDynamics, + frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{&Dynamics, 20_ms}; Vectord<2> r{2, 2}; @@ -35,14 +30,8 @@ TEST(ControlAffinePlantInversionFeedforwardTest, Calculate) { } TEST(ControlAffinePlantInversionFeedforwardTest, CalculateState) { - std::function(const Vectord<2>&)> modelDynamics = [](auto& x) { - return StateDynamics(x); - }; - - Matrixd<2, 1> B{0, 1}; - - frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{modelDynamics, - B, 20_ms}; + frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{ + &StateDynamics, Matrixd<2, 1>{{0.0}, {1.0}}, 20_ms}; Vectord<2> r{2, 2}; Vectord<2> nextR{3, 3};