ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.94k stars 418 forks source link

Compiler warning triggered with -O3 flag #509

Closed WinstonPrivacy closed 1 year ago

WinstonPrivacy commented 1 year ago

Hello,

FTXui has been working quite well so far. However, I just turned on -O3 and am receiving the following compilation error on Linux. Note that FTXui turns on -WError.

` inlined from ‘void ftxui::ScreenInteractive::SigStop()’ at /ftxui/src/ftxui/component/screen_interactive.cpp:661:7: /usr/local/include/c++/12.2.0/bits/cow_string.h:315:14: warning: ‘((std::basic_string<char, std::char_traits, std::allocator >::_Alloc_hider)((char)& + offsetof(std::Task, std::variant<ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::detail::variant::_Variant_base<ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::detail::variant::_Move_assign_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::detail::variant::_Copy_assign_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::detail::variant::_Move_ctor_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::detail::variant::_Copy_ctor_base<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::.std::detail::variant::_Variant_storage<false, ftxui::Event, std::function<void()>, ftxui::AnimationTask>::_M_u)))[4].std::basic_string::_Alloc_hider::_M_p’ may be used uninitialized [-Wmaybe-uninitialized] 315 | struct _Alloc_hider : _Alloc | ^~~~ .../ftxui/src/ftxui/component/screen_interactive.cpp: In member function ‘void ftxui::ScreenInteractive::SigStop()’: .../ftxui/src/ftxui/component/screen_interactive.cpp:661:7: note: ‘anonymous’ declared here

661 | Post([&] { 662 | Uninstall(); 663 | std::cout << reset_cursor_position; 664 | reset_cursorposition = ""; 665 | std::cout << ResetPosition(/clear=/true); 666 | dimx = 0; 667 | dimy_ = 0; 668 | Flush(); 669 | std::raise(SIGTSTP); 670 | Install(); 671 | }); cc1plus: all warnings being treated as errors `

I also note that CLion/GCC is showing an error on the lambda capture function as well ("Attempt to use a deleted function"):

https://imgur.com/sgrRMMH.png

WinstonPrivacy commented 1 year ago

Turning off -Werror doesn't help, unless -O1 is set in which case the code compiles without error.

ArthurSonzogni commented 1 year ago

Hello! Thanks for using FTXUI.

This function catch SIGTSTP, uninstall FTXUI, execute the standard SIGTSTP handler pausing the application, then reinstall FTXUI.

Do you know what is causing the error you are seeing? For me to investigate, I would need to find a way to reproduce. What are you using to use FTXUI. Are you using CMake?

WinstonPrivacy commented 1 year ago

Got pulled off for a bit and am ready to try this. However, I'm not sure what you mean by uninstalling FTXUI as it's included directly in my project (ie: compiled from source as a static library).

I am using CMake but not to install. I just cloned it as a subdirectory within my project.

WinstonPrivacy commented 1 year ago

I ended up rebuilding my environment so it appears that this bug was triggered by a legacy compiler. Using GCC 11.2 , the -O3 flag is working with ftxui now.