From dbe9b150cd0bc44e5b456c149b4cd773b4f67a35 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 21:43:24 +0100 Subject: [PATCH 01/13] Got rid of warnings related to strings --- include/rfl/AnyOf.hpp | 11 ++++---- include/rfl/OneOf.hpp | 14 +++++------ include/rfl/PatternValidator.hpp | 7 ++++-- include/rfl/internal/StringLiteral.hpp | 2 +- include/rfl/parsing/NamedTupleParser.hpp | 7 ++++-- .../rfl/parsing/to_single_error_message.hpp | 25 +++++++++++-------- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/include/rfl/AnyOf.hpp b/include/rfl/AnyOf.hpp index 1baa15a1..6ef15583 100644 --- a/include/rfl/AnyOf.hpp +++ b/include/rfl/AnyOf.hpp @@ -1,6 +1,7 @@ #ifndef RFL_ANYOF_HPP_ #define RFL_ANYOF_HPP_ +#include #include #include #include @@ -28,13 +29,13 @@ struct AnyOf { private: static Error make_error_message(const std::vector& _errors) { - std::string msg = - "Expected at least one of the following validations to pass, but none " - "of them did:"; + std::stringstream stream; + stream << "Expected at least one of the following validations to pass, but " + "none of them did:"; for (size_t i = 0; i < _errors.size(); ++i) { - msg += "\n" + std::to_string(i + 1) + ") " + _errors.at(i).what(); + stream << "\n" << i + 1 << ") " << _errors.at(i).what(); } - return Error(msg); + return Error(stream.str()); } template diff --git a/include/rfl/OneOf.hpp b/include/rfl/OneOf.hpp index 8f7aafd5..c1a8383f 100644 --- a/include/rfl/OneOf.hpp +++ b/include/rfl/OneOf.hpp @@ -1,6 +1,7 @@ #ifndef RFL_ONEOF_HPP_ #define RFL_ONEOF_HPP_ +#include #include #include #include @@ -28,15 +29,14 @@ struct OneOf { private: static Error make_error_message(const std::vector& _errors) { - std::string msg = "Expected exactly 1 out of " + - std::to_string(sizeof...(Cs) + 1) + - " validations to pass, but " + - std::to_string(sizeof...(Cs) + 1 - _errors.size()) + - " of them did. The following errors were generated: "; + std::stringstream stream; + stream << "Expected exactly 1 out of " << sizeof...(Cs) + 1 + << " validations to pass, but " << sizeof...(Cs) + 1 - _errors.size() + << " of them did. The following errors were generated: "; for (size_t i = 0; i < _errors.size(); ++i) { - msg += "\n" + std::to_string(i + 1) + ") " + _errors.at(i).what(); + stream << "\n" << i + 1 << ") " << _errors.at(i).what(); } - return Error(msg); + return Error(stream.str()); } template diff --git a/include/rfl/PatternValidator.hpp b/include/rfl/PatternValidator.hpp index b88aa811..522fd8b8 100644 --- a/include/rfl/PatternValidator.hpp +++ b/include/rfl/PatternValidator.hpp @@ -1,6 +1,7 @@ #ifndef RFL_PATTERNVALIDATOR_HPP_ #define RFL_PATTERNVALIDATOR_HPP_ +#include #include #if __has_include() @@ -25,8 +26,10 @@ struct PatternValidator { if (ctre::match<_regex.arr_>(_str)) { return _str; } else { - return rfl::Error("String '" + _str + "' did not match format '" + - _name.str() + "': '" + _regex.str() + "'."); + std::stringstream stream; + stream << "String '" << _str << "' did not match format '" << _name.str() + << "': '" << _regex.str() << "'."; + return rfl::Error(stream.str()); } } diff --git a/include/rfl/internal/StringLiteral.hpp b/include/rfl/internal/StringLiteral.hpp index 56803ec4..57f6861f 100644 --- a/include/rfl/internal/StringLiteral.hpp +++ b/include/rfl/internal/StringLiteral.hpp @@ -23,7 +23,7 @@ struct StringLiteral { } /// Returns the value as a string. - std::string str() const { return std::string(std::data(arr_), N - 1); } + std::string str() const { return std::string(string_view()); } /// Returns the value as a string. constexpr std::string_view string_view() const { diff --git a/include/rfl/parsing/NamedTupleParser.hpp b/include/rfl/parsing/NamedTupleParser.hpp index d8e866bd..a87224ac 100644 --- a/include/rfl/parsing/NamedTupleParser.hpp +++ b/include/rfl/parsing/NamedTupleParser.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -260,8 +261,10 @@ struct NamedTupleParser { if constexpr (is_required_field) { constexpr auto current_name = internal::nth_element_t<_i, FieldTypes...>::name(); - _errors->emplace_back(Error( - "Field named '" + std::string(current_name) + "' not found.")); + std::stringstream stream; + stream << "Field named '" << std::string(current_name) + << "' not found."; + _errors->emplace_back(Error(stream.str())); } else { if constexpr (!std::is_const_v) { ::new (rfl::get<_i>(_view)) ValueType(); diff --git a/include/rfl/parsing/to_single_error_message.hpp b/include/rfl/parsing/to_single_error_message.hpp index e8601e09..b5e633b9 100644 --- a/include/rfl/parsing/to_single_error_message.hpp +++ b/include/rfl/parsing/to_single_error_message.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_TOSINGLEERRORMESSAGE_HPP_ #include +#include #include #include @@ -17,21 +18,23 @@ inline Error to_single_error_message( if (_errors.size() == 1) { return std::move(_errors[0]); } else { - std::string msg = - _msg_prefix ? *_msg_prefix - : "Found " + std::to_string(_errors.size()) + " errors:"; + std::stringstream stream; + stream << (_msg_prefix + ? *_msg_prefix + : "Found " + std::to_string(_errors.size()) + " errors:"); for (size_t i = 0; i < _errors.size() && i < _err_limit; ++i) { - msg += - "\n" + std::to_string(i + 1) + ") " + - internal::strings::replace_all(_errors.at(i).what(), "\n", "\n "); + stream << "\n" + << i + 1 << ") " + << internal::strings::replace_all(_errors.at(i).what(), "\n", + "\n "); } if (_errors.size() > _err_limit) { - msg += "\n...\nMore than " + std::to_string(_err_limit) + - " errors occurred, but I am only showing the " - "first " + - std::to_string(_err_limit) + "."; + stream << "\n...\nMore than " << _err_limit + << " errors occurred, but I am only showing the " + "first " + << _err_limit << "."; } - return Error(msg); + return Error(stream.str()); } } From fd1009eba016477a7b3d1bb427eeeb0188e27ab1 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 21:50:21 +0100 Subject: [PATCH 02/13] Fixed warning in rfl::Literal --- include/rfl/Literal.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/rfl/Literal.hpp b/include/rfl/Literal.hpp index fc7ce50e..40d0e9d6 100644 --- a/include/rfl/Literal.hpp +++ b/include/rfl/Literal.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -28,10 +27,8 @@ class Literal { using FieldsType = rfl::Tuple...>; public: - using ValueType = - std::conditional_t::max(), - std::uint8_t, std::uint16_t>; + using ValueType = std::conditional_t; /// The number of different fields or different options that the literal /// can assume. From 2d9cecea8b5f3ddf69e2ba351f0eb7c2d3c4ab35 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 21:55:27 +0100 Subject: [PATCH 03/13] Remove -Wextra --- tests/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ef908c0c..e53419b1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,8 +3,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2") if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++20") else() - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -Wall -Wno-sign-compare -Wno-missing-braces -Wno-psabi -pthread -fno-strict-aliasing -fwrapv -O3 -ftemplate-backtrace-limit=0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -Wextra -ggdb -ftemplate-backtrace-limit=0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -ggdb -ftemplate-backtrace-limit=0") endif() if (REFLECTCPP_JSON) From 6dd8c30c8d793dcc40490cb4b821531a0aeaf48a Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 21:55:45 +0100 Subject: [PATCH 04/13] Add -Werror --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e53419b1..867262ee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2") if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++20") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -ggdb -ftemplate-backtrace-limit=0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -Werror -ggdb -ftemplate-backtrace-limit=0") endif() if (REFLECTCPP_JSON) From 19fc224ba9faf486e01a45b1bcd2a61123d0a9a6 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 22:14:04 +0100 Subject: [PATCH 05/13] Got rid of clang warning --- tests/json/test_reflector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/json/test_reflector.cpp b/tests/json/test_reflector.cpp index a177c5cd..2002105d 100644 --- a/tests/json/test_reflector.cpp +++ b/tests/json/test_reflector.cpp @@ -28,7 +28,7 @@ struct Reflector { std::vector children; }; static test_reflector::Parent to(const ReflType& v) noexcept { - return {v.first_name, v.last_name, v.children}; + return {{v.first_name, v.last_name}, v.children}; } static ReflType from(const test_reflector::Parent& v) { @@ -40,8 +40,8 @@ struct Reflector { namespace test_reflector { TEST(json, test_reflector) { - const auto homer = - test_reflector::Parent{"Homer", "Simpson", {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; + const auto homer = test_reflector::Parent{ + "Homer", "Simpson", {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; write_and_read( homer, From 57f71535d95e622d7b26a895d7ff2bac750d72fe Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 22:14:20 +0100 Subject: [PATCH 06/13] Use std::stringstream in the TaggedUnion --- include/rfl/parsing/Parser_tagged_union.hpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/include/rfl/parsing/Parser_tagged_union.hpp b/include/rfl/parsing/Parser_tagged_union.hpp index 937b5e96..06e28a9d 100644 --- a/include/rfl/parsing/Parser_tagged_union.hpp +++ b/include/rfl/parsing/Parser_tagged_union.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_PARSER_TAGGED_UNION_HPP_ #include +#include #include #include "../Result.hpp" @@ -91,10 +92,12 @@ struct Parser, return res; } else { const auto names = PossibleTags::names(); - return Error("Could not parse tagged union, could not match " + - _discriminator.str() + " '" + _disc_value + - "'. The following tags are allowed: " + - internal::strings::join(", ", names)); + std::stringstream stream; + stream << "Could not parse tagged union, could not match " + << _discriminator.str() << " '" << _disc_value + << "'. The following tags are allowed: " + << internal::strings::join(", ", names); + return Error(stream.str()); } } @@ -122,10 +125,12 @@ struct Parser, }; const auto embellish_error = [&](Error&& _e) { - return Error( - "Could not parse tagged union with " - "discrimininator " + - _discriminator.str() + " '" + _disc_value + "': " + _e.what()); + std::stringstream stream; + stream << "Could not parse tagged union with " + "discrimininator " + << _discriminator.str() << " '" << _disc_value + << "': " << _e.what(); + return Error(stream.str()); }; if constexpr (no_field_names_) { From 9b722abd5a1e9cb0db02e40b3a63a816f86e69ef Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 22:23:55 +0100 Subject: [PATCH 07/13] Wrap in braces --- tests/json/test_reflector.cpp | 2 +- tests/json/test_reflector_read.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/json/test_reflector.cpp b/tests/json/test_reflector.cpp index 2002105d..06813f7d 100644 --- a/tests/json/test_reflector.cpp +++ b/tests/json/test_reflector.cpp @@ -41,7 +41,7 @@ namespace test_reflector { TEST(json, test_reflector) { const auto homer = test_reflector::Parent{ - "Homer", "Simpson", {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; + {"Homer", "Simpson"}, {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; write_and_read( homer, diff --git a/tests/json/test_reflector_read.cpp b/tests/json/test_reflector_read.cpp index 27cbd4f2..c9643f95 100644 --- a/tests/json/test_reflector_read.cpp +++ b/tests/json/test_reflector_read.cpp @@ -28,7 +28,7 @@ struct Reflector { std::vector children; }; static test_reflector_read::Parent to(const ReflType& v) noexcept { - return {v.first_name, v.last_name, v.children}; + return {{v.first_name, v.last_name}, v.children}; } }; } // namespace rfl @@ -36,8 +36,8 @@ struct Reflector { namespace test_reflector_read { TEST(json, test_reflector_read) { - const auto homer = - test_reflector_read::Parent{"Homer", "Simpson", {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; + const auto homer = test_reflector_read::Parent{ + "Homer", "Simpson", {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; read( R"({"first_name":"Homer","last_name":"Simpson","children":[{"first_name":"Bart","last_name":"Simpson"},{"first_name":"Lisa","last_name":"Simpson"}]})", From 64c12c89ebc19d043622b867238ab91000baff2e Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 22:28:00 +0100 Subject: [PATCH 08/13] Added more braces --- tests/json/test_reflector_write.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/json/test_reflector_write.cpp b/tests/json/test_reflector_write.cpp index 6e00203a..58b5cb8e 100644 --- a/tests/json/test_reflector_write.cpp +++ b/tests/json/test_reflector_write.cpp @@ -37,8 +37,8 @@ struct Reflector { namespace test_reflector_write { TEST(json, test_reflector_write) { - const auto homer = - test_reflector_write::Parent{"Homer", "Simpson", {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; + const auto homer = test_reflector_write::Parent{ + {"Homer", "Simpson"}, {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; write( homer, From b0ac993308996b893993796e442eae58ccd24311 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 22:31:26 +0100 Subject: [PATCH 09/13] Added yet more braces --- tests/json/test_reflector_read.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/json/test_reflector_read.cpp b/tests/json/test_reflector_read.cpp index c9643f95..bc74a644 100644 --- a/tests/json/test_reflector_read.cpp +++ b/tests/json/test_reflector_read.cpp @@ -37,7 +37,7 @@ namespace test_reflector_read { TEST(json, test_reflector_read) { const auto homer = test_reflector_read::Parent{ - "Homer", "Simpson", {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; + {"Homer", "Simpson"}, {{"Bart", "Simpson"}, {"Lisa", "Simpson"}}}; read( R"({"first_name":"Homer","last_name":"Simpson","children":[{"first_name":"Bart","last_name":"Simpson"},{"first_name":"Lisa","last_name":"Simpson"}]})", From 181a125c6b66dd6e31d62738a15f9dcbed981c84 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 22:40:02 +0100 Subject: [PATCH 10/13] Added more braces, once again --- tests/json_c_arrays_and_inheritance/test_c_array_class3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/json_c_arrays_and_inheritance/test_c_array_class3.cpp b/tests/json_c_arrays_and_inheritance/test_c_array_class3.cpp index 05b32c4c..50cdce08 100644 --- a/tests/json_c_arrays_and_inheritance/test_c_array_class3.cpp +++ b/tests/json_c_arrays_and_inheritance/test_c_array_class3.cpp @@ -9,7 +9,7 @@ namespace test_c_array_class3 { using Test3 = std::array[3]; TEST(json, test_c_array_class3) { - Test3 test3 = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + Test3 test3 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; write_and_read(test3, "[[1,2,3],[4,5,6],[7,8,9]]"); } From be94d706bdd70bbb305882a07c68faeb55720630 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 23:05:46 +0100 Subject: [PATCH 11/13] Use stringstream in the ViewReader --- include/rfl/parsing/ViewReader.hpp | 24 +++++++++++-------- include/rfl/parsing/ViewReaderWithDefault.hpp | 24 +++++++++++-------- ...ReaderWithDefaultAndStrippedFieldNames.hpp | 14 +++++++---- .../ViewReaderWithStrippedFieldNames.hpp | 14 +++++++---- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/include/rfl/parsing/ViewReader.hpp b/include/rfl/parsing/ViewReader.hpp index ea1b4e4f..2221f749 100644 --- a/include/rfl/parsing/ViewReader.hpp +++ b/include/rfl/parsing/ViewReader.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_VIEWREADER_HPP_ #include +#include #include #include #include @@ -52,9 +53,10 @@ class ViewReader { *_already_assigned = true; auto res = Parser::read(_r, _var); if (!res) { - _errors->emplace_back(Error("Failed to parse field '" + - std::string(name) + - "': " + std::move(res.error()->what()))); + std::stringstream stream; + stream << "Failed to parse field '" << std::string(name) + << "': " << res.error()->what(); + _errors->emplace_back(Error(stream.str())); return; } if constexpr (std::is_pointer_v) { @@ -83,9 +85,10 @@ class ViewReader { } auto res = Parser::read(_r, _var); if (!res) { - _errors->emplace_back(Error("Failed to parse field '" + - std::string(_current_name) + - "': " + std::move(res.error()->what()))); + std::stringstream stream; + stream << "Failed to parse field '" << _current_name + << "': " << res.error()->what(); + _errors->emplace_back(Error(stream.str())); return; } extra_fields->emplace(std::string(_current_name), std::move(*res)); @@ -111,10 +114,11 @@ class ViewReader { } } else if constexpr (ProcessorsType::no_extra_fields_) { if (!already_assigned) { - _errors->emplace_back( - Error("Value named '" + std::string(_current_name) + - "' not used. Remove the rfl::NoExtraFields processor or add " - "rfl::ExtraFields to avoid this error message.")); + std::stringstream stream; + stream << "Value named '" << _current_name + << "' not used. Remove the rfl::NoExtraFields processor or add " + "rfl::ExtraFields to avoid this error message."; + _errors->emplace_back(Error(stream.str())); } } } diff --git a/include/rfl/parsing/ViewReaderWithDefault.hpp b/include/rfl/parsing/ViewReaderWithDefault.hpp index 85c80333..f73caee0 100644 --- a/include/rfl/parsing/ViewReaderWithDefault.hpp +++ b/include/rfl/parsing/ViewReaderWithDefault.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_VIEWREADERWITHDEFAULT_HPP_ #include +#include #include #include #include @@ -48,9 +49,10 @@ class ViewReaderWithDefault { *_already_assigned = true; auto res = Parser::read(_r, _var); if (!res) { - _errors->emplace_back(Error("Failed to parse field '" + - std::string(name) + - "': " + std::move(res.error()->what()))); + std::stringstream stream; + stream << "Failed to parse field '" << std::string(name) + << "': " << res.error()->what(); + _errors->emplace_back(Error(stream.str())); return; } if constexpr (std::is_pointer_v) { @@ -73,9 +75,10 @@ class ViewReaderWithDefault { std::remove_pointer_t>; auto res = Parser::read(_r, _var); if (!res) { - _errors->emplace_back(Error("Failed to parse field '" + - std::string(_current_name) + - "': " + std::move(res.error()->what()))); + std::stringstream stream; + stream << "Failed to parse field '" << _current_name + << "': " << res.error()->what(); + _errors->emplace_back(Error(stream.str())); return; } extra_fields->emplace(std::string(_current_name), std::move(*res)); @@ -100,10 +103,11 @@ class ViewReaderWithDefault { } } else if constexpr (ProcessorsType::no_extra_fields_) { if (!already_assigned) { - _errors->emplace_back( - Error("Value named '" + std::string(_current_name) + - "' not used. Remove the rfl::NoExtraFields processor or add " - "rfl::ExtraFields to avoid this error message.")); + std::stringstream stream; + stream << "Value named '" << std::string(_current_name) + << "' not used. Remove the rfl::NoExtraFields processor or add " + "rfl::ExtraFields to avoid this error message."; + _errors->emplace_back(Error(stream.str())); } } } diff --git a/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp b/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp index 7fd72c9b..04f92827 100644 --- a/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp +++ b/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_VIEWREADERWITHDEFAULTANDSTRIPPEDFIELDNAMES_HPP_ #include +#include #include #include #include @@ -30,8 +31,10 @@ class ViewReaderWithDefaultAndStrippedFieldNames { /// used when the field names are stripped. std::optional read(const InputVarType& _var) const { if (i_ == size_) { - return Error("Expected a maximum of " + std::to_string(size_) + - " fields, but got at least one more."); + std::stringstream stream; + stream << "Expected a maximum of " << std::to_string(size_) + << " fields, but got at least one more."; + return Error(stream.str()); } assign_to_field_i(*r_, _var, view_, errors_, i_, std::make_integer_sequence()); @@ -51,9 +54,10 @@ class ViewReaderWithDefaultAndStrippedFieldNames { if (_i == i) { auto res = Parser::read(_r, _var); if (!res) { - _errors->emplace_back(Error("Failed to parse field '" + - std::string(name) + - "': " + std::move(res.error()->what()))); + std::stringstream stream; + stream << "Failed to parse field '" << std::string(name) + << "': " << res.error()->what(); + _errors->emplace_back(Error(stream.str())); return; } if constexpr (std::is_pointer_v) { diff --git a/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp b/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp index 678c0231..5e040bc1 100644 --- a/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp +++ b/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_VIEWREADERWITHSTRIPPEDFIELDNAMES_HPP_ #include +#include #include #include #include @@ -37,8 +38,10 @@ class ViewReaderWithStrippedFieldNames { /// used when the field names are stripped. std::optional read(const InputVarType& _var) const { if (i_ == size_) { - return Error("Expected a maximum of " + std::to_string(size_) + - " fields, but got at least one more."); + std::stringstream stream; + stream << "Expected a maximum of " << std::to_string(size_) + << " fields, but got at least one more."; + return Error(stream.str()); } assign_to_field_i(*r_, _var, view_, errors_, found_, set_, i_, std::make_integer_sequence()); @@ -60,9 +63,10 @@ class ViewReaderWithStrippedFieldNames { std::get(*_found) = true; auto res = Parser::read(_r, _var); if (!res) { - _errors->emplace_back(Error("Failed to parse field '" + - std::string(name) + - "': " + std::move(res.error()->what()))); + std::stringstream stream; + stream << "Failed to parse field '" << std::string(name) + << "': " << res.error()->what(); + _errors->emplace_back(Error(stream.str())); return; } if constexpr (std::is_pointer_v) { From 49130bc94c0a1c3ed20164e13e949b85eddfe914 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 23:28:16 +0100 Subject: [PATCH 12/13] Use stringstream in the FieldVariantReader --- include/rfl/parsing/FieldVariantReader.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/rfl/parsing/FieldVariantReader.hpp b/include/rfl/parsing/FieldVariantReader.hpp index 58ed8459..487ffe2d 100644 --- a/include/rfl/parsing/FieldVariantReader.hpp +++ b/include/rfl/parsing/FieldVariantReader.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -35,10 +36,11 @@ class FieldVariantReader { _disc_value, _var, std::make_integer_sequence()); if (!*field_variant_) { - *field_variant_ = Error( - "Could not parse rfl::Variant, could not match field named " - "'" + - std::string(_disc_value) + "'."); + std::stringstream stream; + stream << "Could not parse rfl::Variant, could not match field named " + "'" + << _disc_value << "'."; + *field_variant_ = Error(stream.str()); } } @@ -62,8 +64,10 @@ class FieldVariantReader { return rfl::Variant(FieldType(std::move(_val))); }; const auto embellish_error = [&](const Error& _e) { - return Error("Could not parse rfl::Variant with field '" + - std::string(_disc_value) + "': " + _e.what()); + std::stringstream stream; + stream << "Could not parse rfl::Variant with field '" + << std::string(_disc_value) << "': " << _e.what(); + return Error(stream.str()); }; *field_variant_ = Parser::read(*r_, _var) .transform(to_variant) From 6aba5ff25fb9c008c020db5d8b80ab7164b9acba Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 31 Oct 2024 23:28:27 +0100 Subject: [PATCH 13/13] Use stringstream in TaggedUnion --- include/rfl/parsing/Parser_tagged_union.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/rfl/parsing/Parser_tagged_union.hpp b/include/rfl/parsing/Parser_tagged_union.hpp index 06e28a9d..e4314cd4 100644 --- a/include/rfl/parsing/Parser_tagged_union.hpp +++ b/include/rfl/parsing/Parser_tagged_union.hpp @@ -158,9 +158,10 @@ struct Parser, }; const auto embellish_error = [](const auto&) { - return Error("Could not parse tagged union: Could not find field '" + - _discriminator.str() + - "' or type of field was not a string."); + std::stringstream stream; + stream << "Could not parse tagged union: Could not find field '" + << _discriminator.str() << "' or type of field was not a string."; + return Error(stream.str()); }; if constexpr (no_field_names_) {