From ac5191c2e8dc8a9bd74275f45cf9ede04a384068 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 30 Oct 2022 06:51:29 +0000 Subject: [PATCH] fix warning --- .gitignore | 1 + CMakeLists.txt | 2 +- example/example.cpp | 2 +- example/json_example.cpp | 6 +++--- iguana/detail/string_stream.hpp | 4 ++-- iguana/json.hpp | 10 ++++------ 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index fcafeae8..09824861 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ *.app build +.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index c673c5cd..c6815be0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17") ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) else() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++17") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -std=c++17") endif(MSVC) set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl") set(IGUANA_DIR ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/example/example.cpp b/example/example.cpp index 993c0479..127d3a9e 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -39,7 +39,7 @@ void test_json() { person p; const char * json = "{ \"name\" : \"tom\", \"age\" : 20}"; - auto r = iguana::json::from_json0(p, json); + [[maybe_unused]]auto r = iguana::json::from_json0(p, json); iguana::string_stream ss; iguana::json::to_json(ss, p); diff --git a/example/json_example.cpp b/example/json_example.cpp index 9f1e4658..456ce687 100644 --- a/example/json_example.cpp +++ b/example/json_example.cpp @@ -111,7 +111,7 @@ void test_disorder() student s1{}; std::string str = "{\"name\":\"tom\",\"id\":1,\"age\":20}"; - bool r = iguana::json::from_json0(s1, str.data(), str.length()); + [[maybe_unused]]bool r = iguana::json::from_json0(s1, str.data(), str.length()); std::string str1 = "{\"name\":\"tom\",\"age\":20,\"id\":1}"; r = iguana::json::from_json0(s1, str1.data(), str1.length()); @@ -139,10 +139,10 @@ int main(void) std::cout << p2.name << " - " << p2.age << std::endl; - // ²âÊÔÒì³£Êý¾Ý,֮ǰµÄ°æ±¾»áÔÚdo.whileÖÐËÀÑ­»· + // �����쳣����,֮ǰ�İ汾����do.while����ѭ�� client::person p3; json_str = "unknownType"; - bool bOK = iguana::json::from_json0(p3, json_str.data(), json_str.length()); //no limitation, but slower + [[maybe_unused]]bool bOK = iguana::json::from_json0(p3, json_str.data(), json_str.length()); //no limitation, but slower return 0; } diff --git a/iguana/detail/string_stream.hpp b/iguana/detail/string_stream.hpp index 98903b87..8f12b4e4 100644 --- a/iguana/detail/string_stream.hpp +++ b/iguana/detail/string_stream.hpp @@ -20,8 +20,8 @@ namespace iguana enum { INIT_BUFF_SIZE = 1024 }; basic_string_stream() - : m_length(INIT_BUFF_SIZE) - , m_status(good) + : m_status(good) + , m_length(INIT_BUFF_SIZE) { this->m_header_ptr = this->alloc.allocate(INIT_BUFF_SIZE); this->m_read_ptr = this->m_header_ptr; diff --git a/iguana/json.hpp b/iguana/json.hpp index ffdd4d17..97b0afd6 100644 --- a/iguana/json.hpp +++ b/iguana/json.hpp @@ -261,7 +261,7 @@ static bool g_has_error = false; class reader_t { public: reader_t(const char *ptr = nullptr, size_t len = -1) - : ptr_((char *)ptr), len_(len) { + : len_(len), ptr_((char *)ptr) { if (ptr == nullptr) { end_mark_ = true; } else if (len == 0) { @@ -437,7 +437,7 @@ class reader_t { inline char char_to_hex(char v) { if (v < 'f') { - v = table[v]; + v = table[int(v)]; } else { v = 16; } @@ -896,7 +896,7 @@ read_json(reader_t &rd, T &val, bool unorder = false) { } #define MIN_NUMBER_VALUE 1e-8 -inline void read_json(reader_t &rd, bool &val) { +inline void read_json(reader_t &rd, bool &val, bool unorder = false) { auto &tok = rd.peek(); switch (tok.type) { case token::t_string: { @@ -930,7 +930,7 @@ inline void read_json(reader_t &rd, bool &val) { rd.next(); } -inline void read_json(reader_t &rd, std::string &val) { +inline void read_json(reader_t &rd, std::string &val, bool unorder = false) { auto &tok = rd.peek(); if (tok.type == token::t_string) { val.assign(tok.str.str, tok.str.len); @@ -1104,7 +1104,6 @@ template inline void assign(reader_t &rd, T &t) { template inline std::enable_if_t>::value, bool> from_json(T &&t, const char *buf, size_t len = -1) { - using U = std::decay_t; g_has_error = false; reader_t rd(buf, len); rd.next(); @@ -1154,7 +1153,6 @@ inline bool from_json0(T &&t, const char *buf, size_t len = -1) { template ::value>> constexpr void do_read0(reader_t &rd, T &&t) { using M = decltype(iguana_reflect_members(std::forward(t))); - constexpr auto Count = M::value(); auto tp = M::apply_impl(); constexpr auto Size = M::value();