From 6c6774dbf59c7d42270f697510ae2b6819fb7389 Mon Sep 17 00:00:00 2001 From: Alex Dadukin Date: Wed, 10 Jul 2024 18:07:14 +0100 Subject: [PATCH 1/2] Update compilation parameters: increase warnings severity --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fda8759..f70995a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,12 @@ add_library(jsonc src/json.cpp ) +if(MSVC) + target_compile_options(jsonc PRIVATE /W4 /WX) +else() + target_compile_options(jsonc PRIVATE -Wall -Wextra -Wpedantic -Werror) +endif() + set_property(TARGET jsonc PROPERTY COMPILE_WARNING_AS_ERROR ON) target_include_directories(jsonc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) From e0d49836c10223625455b1acc057c0feac746d7a Mon Sep 17 00:00:00 2001 From: Alex Dadukin Date: Wed, 10 Jul 2024 18:10:00 +0100 Subject: [PATCH 2/2] Fix RTO prevention: remove move calls that prevent copy elision --- include/json.h | 2 +- include/json_beautifier.h | 2 +- include/json_minifier.h | 2 +- src/json.cpp | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/json.h b/include/json.h index 92595ff..e4a9646 100644 --- a/include/json.h +++ b/include/json.h @@ -377,7 +377,7 @@ class Json { keys.insert(key); } - return std::move(keys); + return keys; } bool add(const Json& that) { diff --git a/include/json_beautifier.h b/include/json_beautifier.h index b968312..147e735 100644 --- a/include/json_beautifier.h +++ b/include/json_beautifier.h @@ -45,7 +45,7 @@ class JsonBeautifier: public JsonVisitor { } inline std::string beautifiedJson() const { - return std::move(_stream.str()); + return _stream.str(); } uint16_t _depth; diff --git a/include/json_minifier.h b/include/json_minifier.h index ec9eaf9..73a10cc 100644 --- a/include/json_minifier.h +++ b/include/json_minifier.h @@ -33,7 +33,7 @@ class JsonMinifier: public JsonVisitor { } inline std::string minifiedJson() const { - return std::move(_stream.str()); + return _stream.str(); } std::stringstream _stream; diff --git a/src/json.cpp b/src/json.cpp index 236df20..1e9a839 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -12,21 +12,21 @@ const Json& Json::null() { } Json Json::array() { - return std::move(Json(array_t())); + return Json(array_t()); } Json Json::object() { - return std::move(Json(object_t())); + return Json(object_t()); } std::optional Json::fromJson(const std::string& json) { __internal::JsonParser parser; - return std::move(parser.parse(json)); + return parser.parse(json); } std::string Json::toJson(const Json& json) { JsonMinifier minifier; - return std::move(minifier.minify(json)); + return minifier.minify(json); } } // namespace json