summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/warnings.cmake17
-rw-r--r--include/fud_format.hpp26
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 <concepts>
#include <cstdint>
-#include <format>
#include <limits>
#include <variant>
#include <cstdio>
@@ -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 <size_t N>
- 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<FormatAlign> from(utf8 letter)
{
- FormatAlign formatAlign;
+ FormatAlign formatAlign{};
switch (letter) {
case '<':
formatAlign.value = Value::Left;
@@ -247,7 +246,7 @@ template <size_t Size>
struct FormatArguments {
Array<FormatArgument, Size> arguments;
- constexpr size_t size() const
+ [[nodiscard]] constexpr size_t size() const
{
return Size;
}
@@ -260,13 +259,11 @@ struct FormatArguments {
template <typename... Args>
static auto makeFormatArguments(Args&&... args) -> FormatArguments
{
- return FormatArguments{Array<FormatArgument, Size>{{FormatArgument{args}...}}};
+ return FormatArguments{Array<FormatArgument, Size>{{FormatArgument{std::forward<Args>(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<uint64_t>(value);
}
+ // NOLINTNEXTLINE(bugprone-branch-clone)
if constexpr (std::is_same_v<T, char>) {
return fillUnsignedBuffer(buffer, static_cast<uint8_t>(unsignedValue), bufferLength, radix, uppercase);
} else if constexpr (std::is_same_v<T, int8_t>) {
@@ -735,7 +733,7 @@ FudStatus fillSignedBuffer(IntCharArray& buffer, T value, uint8_t& bufferLength,
} else if constexpr (std::is_same_v<T, int32_t>) {
return fillUnsignedBuffer(buffer, static_cast<uint32_t>(unsignedValue), bufferLength, radix, uppercase);
} else if constexpr (std::is_same_v<T, int64_t>) {
- return fillUnsignedBuffer(buffer, static_cast<uint64_t>(unsignedValue), bufferLength, radix, uppercase);
+ return fillUnsignedBuffer(buffer, unsignedValue, bufferLength, radix, uppercase);
}
}
@@ -1294,10 +1292,13 @@ template <typename Sink, typename T>
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 <typename Sink>
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<const char*>(arg));
}