From eb9a701fd7429d1e1c354583a785f859453faeea Mon Sep 17 00:00:00 2001 From: Stefan Ravn van Overeem Date: Sat, 19 Aug 2023 11:20:04 +0200 Subject: [PATCH] Add -Wuseless-cast to FTXUI_DEV_WARNINGS (#728) Add the -Wuseless-cast to the FTXUI_DEV_WARNINGS and fix the compiler complaints about useless casts --- cmake/ftxui_set_options.cmake | 4 ++++ src/ftxui/component/container.cpp | 4 ++-- src/ftxui/component/terminal_input_parser.cpp | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmake/ftxui_set_options.cmake b/cmake/ftxui_set_options.cmake index a269286..d01cafe 100644 --- a/cmake/ftxui_set_options.cmake +++ b/cmake/ftxui_set_options.cmake @@ -77,6 +77,10 @@ function(ftxui_set_options library) target_compile_options(${library} PRIVATE "-Wpedantic") target_compile_options(${library} PRIVATE "-Wshadow") target_compile_options(${library} PRIVATE "-Wunused") + + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${library} PRIVATE "-Wuseless-cast") + endif() endif() endif() diff --git a/src/ftxui/component/container.cpp b/src/ftxui/component/container.cpp index 01e724f..d8a0482 100644 --- a/src/ftxui/component/container.cpp +++ b/src/ftxui/component/container.cpp @@ -82,8 +82,8 @@ class ContainerBase : public ComponentBase { return; } for (size_t offset = 1; offset < children_.size(); ++offset) { - const size_t i = ((size_t(*selector_ + offset * dir + children_.size())) % - children_.size()); + const size_t i = + (*selector_ + offset * dir + children_.size()) % children_.size(); if (children_[i]->Focusable()) { *selector_ = int(i); return; diff --git a/src/ftxui/component/terminal_input_parser.cpp b/src/ftxui/component/terminal_input_parser.cpp index 5dbd28e..c60c4f0 100644 --- a/src/ftxui/component/terminal_input_parser.cpp +++ b/src/ftxui/component/terminal_input_parser.cpp @@ -201,7 +201,7 @@ TerminalInputParser::Output TerminalInputParser::Parse() { // Then some sequences are illegal if it exist a shorter representation of the // same codepoint. TerminalInputParser::Output TerminalInputParser::ParseUTF8() { - auto head = static_cast(Current()); + auto head = Current(); unsigned char selector = 0b1000'0000; // NOLINT // The non code-point part of the first byte. @@ -234,7 +234,7 @@ TerminalInputParser::Output TerminalInputParser::ParseUTF8() { } // Invalid continuation byte. - head = static_cast(Current()); + head = Current(); if ((head & 0b1100'0000) != 0b1000'0000) { // NOLINT return DROP; } @@ -322,7 +322,7 @@ TerminalInputParser::Output TerminalInputParser::ParseCSI() { if (Current() >= '0' && Current() <= '9') { argument *= 10; // NOLINT - argument += int(Current() - '0'); + argument += Current() - '0'; continue; }