From 908fdf06b41f9084d719a4b517c868b1ad29a9ac Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 2 Jan 2025 16:55:06 -0600 Subject: Fix warnings from clang-tidy in fud_format.hpp --- cmake/warnings.cmake | 17 +++++++++-------- include/fud_format.hpp | 26 ++++++++++++++------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cmake/warnings.cmake b/cmake/warnings.cmake index 1787263..909c35c 100644 --- a/cmake/warnings.cmake +++ b/cmake/warnings.cmake @@ -4,15 +4,16 @@ set(FUD_WARNINGS -Wall -Wextra + # TODO: use generator expressions # gcc specific - # -Wstrict-null-sentinel - # -Wsuggest-final-types - # -Wsuggest-final-methods - # -Wimplicit-fallthrough=5 - # -Wduplicated-branches - # -Wstack-usage=2048 # GCC specific - # -Wduplicated-cond - # -Wlogical-op + -Wstrict-null-sentinel + -Wsuggest-final-types + -Wsuggest-final-methods + -Wimplicit-fallthrough=5 + -Wduplicated-branches + -Wstack-usage=2048 # GCC specific + -Wduplicated-cond + -Wlogical-op # -pedantic -Wno-error=pedantic diff --git a/include/fud_format.hpp b/include/fud_format.hpp index 9be3dd9..8dd2231 100644 --- a/include/fud_format.hpp +++ b/include/fud_format.hpp @@ -30,9 +30,7 @@ #include "fud_string_view.hpp" #include "fud_utf8.hpp" -#include #include -#include #include #include #include @@ -41,16 +39,17 @@ namespace fud { // TODO: constants file? constexpr size_t bitsPerOctal = 3; -constexpr size_t maxIntCharCount = bitsPerOctal * sizeof(uint64_t) + 4; +constexpr size_t maxIntCharCount = (bitsPerOctal * sizeof(uint64_t)) + 4; struct FormatString { template - consteval FormatString(const utf8 (&input)[N]) : m_size{N - 1}, m_data{input} + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) + consteval FormatString(const utf8 (&input)[N]) : m_size{N - 1}, m_data{input} { static_assert(N > 0); } - StringView view() + [[nodiscard]] StringView view() const { return StringView{m_size, m_data}; } @@ -75,7 +74,7 @@ struct FormatAlign { constexpr static Option from(utf8 letter) { - FormatAlign formatAlign; + FormatAlign formatAlign{}; switch (letter) { case '<': formatAlign.value = Value::Left; @@ -247,7 +246,7 @@ template struct FormatArguments { Array arguments; - constexpr size_t size() const + [[nodiscard]] constexpr size_t size() const { return Size; } @@ -260,13 +259,11 @@ struct FormatArguments { template static auto makeFormatArguments(Args&&... args) -> FormatArguments { - return FormatArguments{Array{{FormatArgument{args}...}}}; + return FormatArguments{Array{{FormatArgument{std::forward(args)}...}}}; } }; -static_assert(sizeof(FormatArguments<1>) > 0); - -enum class FormatCharMode +enum class FormatCharMode : uint8_t { Unchecked, AsciiOnly, @@ -726,6 +723,7 @@ FudStatus fillSignedBuffer(IntCharArray& buffer, T value, uint8_t& bufferLength, } else { unsignedValue = static_cast(value); } + // NOLINTNEXTLINE(bugprone-branch-clone) if constexpr (std::is_same_v) { return fillUnsignedBuffer(buffer, static_cast(unsignedValue), bufferLength, radix, uppercase); } else if constexpr (std::is_same_v) { @@ -735,7 +733,7 @@ FudStatus fillSignedBuffer(IntCharArray& buffer, T value, uint8_t& bufferLength, } else if constexpr (std::is_same_v) { return fillUnsignedBuffer(buffer, static_cast(unsignedValue), bufferLength, radix, uppercase); } else if constexpr (std::is_same_v) { - return fillUnsignedBuffer(buffer, static_cast(unsignedValue), bufferLength, radix, uppercase); + return fillUnsignedBuffer(buffer, unsignedValue, bufferLength, radix, uppercase); } } @@ -1294,10 +1292,13 @@ template using FormatType::GeneralLower, FormatType::GeneralUpper; using FormatType::ScientificLower, FormatType::ScientificUpper; + // NOLINTNEXTLINE(bugprone-branch-clone) if (floatSpec.formatType == FloatHexLower || floatSpec.formatType == FloatHexUpper) { + // do nothing - not implemented } else if (floatSpec.formatType == ScientificLower || floatSpec.formatType == ScientificUpper) { return formatScientific(sink, floatSpec, decimalRepr, uppercase); } else if (floatSpec.formatType == FixedLower || floatSpec.formatType == FixedUpper) { + // do nothing - not implemented } else if (floatSpec.formatType == GeneralLower || floatSpec.formatType == GeneralUpper) { } else { result.status = FudStatus::FormatInvalid; @@ -1385,6 +1386,7 @@ FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& for template FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& formatSpec, const utf8* arg) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return format(sink, formatMode, formatSpec, reinterpret_cast(arg)); } -- cgit v1.2.3