Closed suiji closed 1 year ago
This is a known problem. I had posted comments about it at my website download page but not in the Readme.md file at github. I have now added those comments. I resolved the issue by disabling the warning in std_function.h.
The warning/error can also be circumvented by setting the two members directly, instead of calling Set(). If the problem is not showing up in the Debug build, it may be an artifact of more aggressive inlining in the Release build. As to why the function object's copy constructor sees the lambda as uninitialized, though ....
Thank you for suggesting the fix. I thought there were other files generating the same warning/error, but with the PVWUpdater.cpp modification the code now compiles without warning on Fedora 37 gcc 12.2.1. (The code compiles correctly on Ubuntu 22.04.1 LTS gcc 11.3.0 and using MSVS 2022 17.4.5 with and without the code modification.) I have uploaded the modification.
Line 14 of PVWUpdater.cpp precipitates a warning during compilation of the static release build under g++ 12.2.1 on Fedora 37. The complaint appears to be related to the lambda appearing in the call to Set().
A trace of the error message appears below:
In copy constructor ‘std::function<_Res(_ArgTypes ...)>::function(const std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {const std::shared_ptr&}]’,
inlined from ‘std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(const std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {const std::shared_ptr&}]’ at /usr/include/c++/12/bits/std_function.h:471:2,
inlined from ‘void gte::PVWUpdater::Set(const std::shared_ptr&, const gte::BufferUpdater&)’ at PVWWUpdater.cpp:25:16,
inlined from ‘gte::PVWUpdater::PVWUpdater()’ at PVWUpdater.cpp:14:9:
/usr/include/c++/12/bits/std_function.h:391:17: error: ‘’ may be used uninitialized [-Werror=maybe-uninitialized]
391 | x._M_manager(_M_functor, x._M_functor, __clone_functor);
| &)>; _ArgTypes = {const std::shared_ptr&}]’ declared here
267 | _M_manager(_Any_data& dest, const _Any_data& source,
| ^’ declared here
14 | Set(nullptr, [](std::shared_ptr const&) {});
|
~~^~~~ /usr/include/c++/12/bits/std_function.h: In constructor ‘gte::PVWUpdater::PVWUpdater()’: /usr/include/c++/12/bits/std_function.h:267: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 = void; _Functor = gte::PVWUpdater::PVWUpdater()::<lambda(const std::shared_ptr~~~~~ PVWUpdater.cpp:14:9: note: ‘~^~~~~~~~~~cc1plus: all warnings being treated as errors