From fd8363a62cc2c1318a0b58b442c3fbc451554fa2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 1 May 2021 20:23:19 +0100 Subject: Fixup clang, cppcheck and iwyu warnings --- lib/jsonParse-persistence.cpp | 2 ++ lib/jsonParse.impl.cpp | 7 ++----- lib/jsonParse.ll | 3 ++- lib/persistence.h | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/jsonParse-persistence.cpp b/lib/jsonParse-persistence.cpp index 7c00773..dce9d3c 100644 --- a/lib/jsonParse-persistence.cpp +++ b/lib/jsonParse-persistence.cpp @@ -1,4 +1,6 @@ #include "jsonParse-persistence.h" +#include +#include namespace Persistence { void diff --git a/lib/jsonParse.impl.cpp b/lib/jsonParse.impl.cpp index 4d13eae..0913847 100644 --- a/lib/jsonParse.impl.cpp +++ b/lib/jsonParse.impl.cpp @@ -25,7 +25,7 @@ json::jsonParser::appendEscape(unsigned long cp, std::string & str) str += char((cp >> 6) + 192); str += char((cp & 63) + 128); } - else if (0xd800 <= cp && cp <= 0xdfff) { + else if ((0xd800 <= cp && cp <= 0xdfff) || cp > 0x10FFFF) { throw std::range_error("Invalid UTF-8 sequence"); } else if (cp <= 0xFFFF) { @@ -33,13 +33,10 @@ json::jsonParser::appendEscape(unsigned long cp, std::string & str) str += char(((cp >> 6) & 63) + 128); str += char((cp & 63) + 128); } - else if (cp <= 0x10FFFF) { + else { str += char((cp >> 18) + 240); str += char(((cp >> 12) & 63) + 128); str += char(((cp >> 6) & 63) + 128); str += char((cp & 63) + 128); } - else { - throw std::range_error("Invalid UTF-8 sequence"); - } } diff --git a/lib/jsonParse.ll b/lib/jsonParse.ll index c9c708c..ab09e80 100644 --- a/lib/jsonParse.ll +++ b/lib/jsonParse.ll @@ -17,7 +17,6 @@ class jsonBaseFlexLexer; #ifdef __clang__ #pragma clang diagnostic ignored "-Wnull-conversion" #endif -[[maybe_unused]]static constexpr auto x=getpid; %} beginobj "{" @@ -155,4 +154,6 @@ text [^\\\"]* <*>. { LexerError("Unexpected input"); + // Make iwyu think unistd.h is required + [[maybe_unused]]static constexpr auto x=getpid; } diff --git a/lib/persistence.h b/lib/persistence.h index 5d5fb0f..519cb0e 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,7 @@ namespace Persistence { virtual void beginObject(Stack &); virtual void endObject(Stack &); virtual void beforeValue(Stack &); - virtual SelectionPtr select(const std::string &); + [[nodiscard]] virtual SelectionPtr select(const std::string &); }; template struct SelectionT; @@ -49,14 +50,14 @@ namespace Persistence { { } - static SelectionPtr + [[nodiscard]] static SelectionPtr make(T & value) { return make_s>(value); } template - static SelectionPtr + [[nodiscard]] static SelectionPtr make_s(T & value) { return std::make_unique(value); @@ -77,10 +78,10 @@ namespace Persistence { }; struct PersistenceStore { - template inline bool persistType() const; + template [[nodiscard]] inline bool persistType() const; template - inline bool + [[nodiscard]] inline bool persistValue(const std::string_view key, T & value) { if (key == name) { @@ -148,7 +149,7 @@ namespace Persistence { virtual bool persist(PersistenceStore & store) = 0; template - constexpr static auto + [[nodiscard]] constexpr static auto typeName() { constexpr std::string_view name {__PRETTY_FUNCTION__}; @@ -159,8 +160,8 @@ namespace Persistence { template static void addFactory() __attribute__((constructor)); static void addFactory(const std::string_view, std::function()>, std::function()>); - static std::unique_ptr callFactory(const std::string_view); - static std::shared_ptr callSharedFactory(const std::string_view); + [[nodiscard]] static std::unique_ptr callFactory(const std::string_view); + [[nodiscard]] static std::shared_ptr callSharedFactory(const std::string_view); }; template @@ -223,7 +224,7 @@ namespace Persistence { using SelectionV::SelectionV; - SelectionPtr + [[nodiscard]] SelectionPtr select(const std::string & mbr) override { using namespace std::literals; -- cgit v1.2.3