Skip to content

Commit 458ca09

Browse files
Remove warnings generated by GCC and Clang (#243)
1 parent ebe3301 commit 458ca09

18 files changed

+123
-91
lines changed

include/rfl/AnyOf.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RFL_ANYOF_HPP_
22
#define RFL_ANYOF_HPP_
33

4+
#include <sstream>
45
#include <string>
56
#include <utility>
67
#include <vector>
@@ -28,13 +29,13 @@ struct AnyOf {
2829

2930
private:
3031
static Error make_error_message(const std::vector<Error>& _errors) {
31-
std::string msg =
32-
"Expected at least one of the following validations to pass, but none "
33-
"of them did:";
32+
std::stringstream stream;
33+
stream << "Expected at least one of the following validations to pass, but "
34+
"none of them did:";
3435
for (size_t i = 0; i < _errors.size(); ++i) {
35-
msg += "\n" + std::to_string(i + 1) + ") " + _errors.at(i).what();
36+
stream << "\n" << i + 1 << ") " << _errors.at(i).what();
3637
}
37-
return Error(msg);
38+
return Error(stream.str());
3839
}
3940

4041
template <class T, class Head, class... Tail>

include/rfl/Literal.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <compare>
55
#include <cstdint>
66
#include <functional>
7-
#include <limits>
87
#include <string>
98
#include <tuple>
109
#include <type_traits>
@@ -28,10 +27,8 @@ class Literal {
2827
using FieldsType = rfl::Tuple<LiteralHelper<fields_>...>;
2928

3029
public:
31-
using ValueType =
32-
std::conditional_t<sizeof...(fields_) <=
33-
std::numeric_limits<std::uint8_t>::max(),
34-
std::uint8_t, std::uint16_t>;
30+
using ValueType = std::conditional_t<sizeof...(fields_) <= 255, std::uint8_t,
31+
std::uint16_t>;
3532

3633
/// The number of different fields or different options that the literal
3734
/// can assume.

include/rfl/OneOf.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RFL_ONEOF_HPP_
22
#define RFL_ONEOF_HPP_
33

4+
#include <sstream>
45
#include <string>
56
#include <utility>
67
#include <vector>
@@ -28,15 +29,14 @@ struct OneOf {
2829

2930
private:
3031
static Error make_error_message(const std::vector<Error>& _errors) {
31-
std::string msg = "Expected exactly 1 out of " +
32-
std::to_string(sizeof...(Cs) + 1) +
33-
" validations to pass, but " +
34-
std::to_string(sizeof...(Cs) + 1 - _errors.size()) +
35-
" of them did. The following errors were generated: ";
32+
std::stringstream stream;
33+
stream << "Expected exactly 1 out of " << sizeof...(Cs) + 1
34+
<< " validations to pass, but " << sizeof...(Cs) + 1 - _errors.size()
35+
<< " of them did. The following errors were generated: ";
3636
for (size_t i = 0; i < _errors.size(); ++i) {
37-
msg += "\n" + std::to_string(i + 1) + ") " + _errors.at(i).what();
37+
stream << "\n" << i + 1 << ") " << _errors.at(i).what();
3838
}
39-
return Error(msg);
39+
return Error(stream.str());
4040
}
4141

4242
template <class T, class Head, class... Tail>

include/rfl/PatternValidator.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RFL_PATTERNVALIDATOR_HPP_
22
#define RFL_PATTERNVALIDATOR_HPP_
33

4+
#include <sstream>
45
#include <string>
56

67
#if __has_include(<ctre.hpp>)
@@ -25,8 +26,10 @@ struct PatternValidator {
2526
if (ctre::match<_regex.arr_>(_str)) {
2627
return _str;
2728
} else {
28-
return rfl::Error("String '" + _str + "' did not match format '" +
29-
_name.str() + "': '" + _regex.str() + "'.");
29+
std::stringstream stream;
30+
stream << "String '" << _str << "' did not match format '" << _name.str()
31+
<< "': '" << _regex.str() << "'.";
32+
return rfl::Error(stream.str());
3033
}
3134
}
3235

include/rfl/internal/StringLiteral.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct StringLiteral {
2323
}
2424

2525
/// Returns the value as a string.
26-
std::string str() const { return std::string(std::data(arr_), N - 1); }
26+
std::string str() const { return std::string(string_view()); }
2727

2828
/// Returns the value as a string.
2929
constexpr std::string_view string_view() const {

include/rfl/parsing/FieldVariantReader.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <array>
55
#include <optional>
6+
#include <sstream>
67
#include <string_view>
78
#include <type_traits>
89
#include <utility>
@@ -35,10 +36,11 @@ class FieldVariantReader {
3536
_disc_value, _var,
3637
std::make_integer_sequence<int, sizeof...(FieldTypes)>());
3738
if (!*field_variant_) {
38-
*field_variant_ = Error(
39-
"Could not parse rfl::Variant, could not match field named "
40-
"'" +
41-
std::string(_disc_value) + "'.");
39+
std::stringstream stream;
40+
stream << "Could not parse rfl::Variant, could not match field named "
41+
"'"
42+
<< _disc_value << "'.";
43+
*field_variant_ = Error(stream.str());
4244
}
4345
}
4446

@@ -62,8 +64,10 @@ class FieldVariantReader {
6264
return rfl::Variant<FieldTypes...>(FieldType(std::move(_val)));
6365
};
6466
const auto embellish_error = [&](const Error& _e) {
65-
return Error("Could not parse rfl::Variant with field '" +
66-
std::string(_disc_value) + "': " + _e.what());
67+
std::stringstream stream;
68+
stream << "Could not parse rfl::Variant with field '"
69+
<< std::string(_disc_value) << "': " << _e.what();
70+
return Error(stream.str());
6771
};
6872
*field_variant_ = Parser<R, W, ValueType, ProcessorsType>::read(*r_, _var)
6973
.transform(to_variant)

include/rfl/parsing/NamedTupleParser.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <array>
55
#include <bit>
66
#include <map>
7+
#include <sstream>
78
#include <tuple>
89
#include <type_traits>
910
#include <unordered_map>
@@ -260,8 +261,10 @@ struct NamedTupleParser {
260261
if constexpr (is_required_field) {
261262
constexpr auto current_name =
262263
internal::nth_element_t<_i, FieldTypes...>::name();
263-
_errors->emplace_back(Error(
264-
"Field named '" + std::string(current_name) + "' not found."));
264+
std::stringstream stream;
265+
stream << "Field named '" << std::string(current_name)
266+
<< "' not found.";
267+
_errors->emplace_back(Error(stream.str()));
265268
} else {
266269
if constexpr (!std::is_const_v<ValueType>) {
267270
::new (rfl::get<_i>(_view)) ValueType();

include/rfl/parsing/Parser_tagged_union.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RFL_PARSING_PARSER_TAGGED_UNION_HPP_
33

44
#include <map>
5+
#include <sstream>
56
#include <type_traits>
67

78
#include "../Result.hpp"
@@ -91,10 +92,12 @@ struct Parser<R, W, TaggedUnion<_discriminator, AlternativeTypes...>,
9192
return res;
9293
} else {
9394
const auto names = PossibleTags::names();
94-
return Error("Could not parse tagged union, could not match " +
95-
_discriminator.str() + " '" + _disc_value +
96-
"'. The following tags are allowed: " +
97-
internal::strings::join(", ", names));
95+
std::stringstream stream;
96+
stream << "Could not parse tagged union, could not match "
97+
<< _discriminator.str() << " '" << _disc_value
98+
<< "'. The following tags are allowed: "
99+
<< internal::strings::join(", ", names);
100+
return Error(stream.str());
98101
}
99102
}
100103

@@ -122,10 +125,12 @@ struct Parser<R, W, TaggedUnion<_discriminator, AlternativeTypes...>,
122125
};
123126

124127
const auto embellish_error = [&](Error&& _e) {
125-
return Error(
126-
"Could not parse tagged union with "
127-
"discrimininator " +
128-
_discriminator.str() + " '" + _disc_value + "': " + _e.what());
128+
std::stringstream stream;
129+
stream << "Could not parse tagged union with "
130+
"discrimininator "
131+
<< _discriminator.str() << " '" << _disc_value
132+
<< "': " << _e.what();
133+
return Error(stream.str());
129134
};
130135

131136
if constexpr (no_field_names_) {
@@ -153,9 +158,10 @@ struct Parser<R, W, TaggedUnion<_discriminator, AlternativeTypes...>,
153158
};
154159

155160
const auto embellish_error = [](const auto&) {
156-
return Error("Could not parse tagged union: Could not find field '" +
157-
_discriminator.str() +
158-
"' or type of field was not a string.");
161+
std::stringstream stream;
162+
stream << "Could not parse tagged union: Could not find field '"
163+
<< _discriminator.str() << "' or type of field was not a string.";
164+
return Error(stream.str());
159165
};
160166

161167
if constexpr (no_field_names_) {

include/rfl/parsing/ViewReader.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RFL_PARSING_VIEWREADER_HPP_
33

44
#include <array>
5+
#include <sstream>
56
#include <string_view>
67
#include <type_traits>
78
#include <utility>
@@ -52,9 +53,10 @@ class ViewReader {
5253
*_already_assigned = true;
5354
auto res = Parser<R, W, T, ProcessorsType>::read(_r, _var);
5455
if (!res) {
55-
_errors->emplace_back(Error("Failed to parse field '" +
56-
std::string(name) +
57-
"': " + std::move(res.error()->what())));
56+
std::stringstream stream;
57+
stream << "Failed to parse field '" << std::string(name)
58+
<< "': " << res.error()->what();
59+
_errors->emplace_back(Error(stream.str()));
5860
return;
5961
}
6062
if constexpr (std::is_pointer_v<OriginalType>) {
@@ -83,9 +85,10 @@ class ViewReader {
8385
}
8486
auto res = Parser<R, W, T, ProcessorsType>::read(_r, _var);
8587
if (!res) {
86-
_errors->emplace_back(Error("Failed to parse field '" +
87-
std::string(_current_name) +
88-
"': " + std::move(res.error()->what())));
88+
std::stringstream stream;
89+
stream << "Failed to parse field '" << _current_name
90+
<< "': " << res.error()->what();
91+
_errors->emplace_back(Error(stream.str()));
8992
return;
9093
}
9194
extra_fields->emplace(std::string(_current_name), std::move(*res));
@@ -111,10 +114,11 @@ class ViewReader {
111114
}
112115
} else if constexpr (ProcessorsType::no_extra_fields_) {
113116
if (!already_assigned) {
114-
_errors->emplace_back(
115-
Error("Value named '" + std::string(_current_name) +
116-
"' not used. Remove the rfl::NoExtraFields processor or add "
117-
"rfl::ExtraFields to avoid this error message."));
117+
std::stringstream stream;
118+
stream << "Value named '" << _current_name
119+
<< "' not used. Remove the rfl::NoExtraFields processor or add "
120+
"rfl::ExtraFields to avoid this error message.";
121+
_errors->emplace_back(Error(stream.str()));
118122
}
119123
}
120124
}

include/rfl/parsing/ViewReaderWithDefault.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RFL_PARSING_VIEWREADERWITHDEFAULT_HPP_
33

44
#include <array>
5+
#include <sstream>
56
#include <string_view>
67
#include <type_traits>
78
#include <utility>
@@ -48,9 +49,10 @@ class ViewReaderWithDefault {
4849
*_already_assigned = true;
4950
auto res = Parser<R, W, T, ProcessorsType>::read(_r, _var);
5051
if (!res) {
51-
_errors->emplace_back(Error("Failed to parse field '" +
52-
std::string(name) +
53-
"': " + std::move(res.error()->what())));
52+
std::stringstream stream;
53+
stream << "Failed to parse field '" << std::string(name)
54+
<< "': " << res.error()->what();
55+
_errors->emplace_back(Error(stream.str()));
5456
return;
5557
}
5658
if constexpr (std::is_pointer_v<OriginalType>) {
@@ -73,9 +75,10 @@ class ViewReaderWithDefault {
7375
std::remove_pointer_t<typename ExtraFieldsType::Type>>;
7476
auto res = Parser<R, W, T, ProcessorsType>::read(_r, _var);
7577
if (!res) {
76-
_errors->emplace_back(Error("Failed to parse field '" +
77-
std::string(_current_name) +
78-
"': " + std::move(res.error()->what())));
78+
std::stringstream stream;
79+
stream << "Failed to parse field '" << _current_name
80+
<< "': " << res.error()->what();
81+
_errors->emplace_back(Error(stream.str()));
7982
return;
8083
}
8184
extra_fields->emplace(std::string(_current_name), std::move(*res));
@@ -100,10 +103,11 @@ class ViewReaderWithDefault {
100103
}
101104
} else if constexpr (ProcessorsType::no_extra_fields_) {
102105
if (!already_assigned) {
103-
_errors->emplace_back(
104-
Error("Value named '" + std::string(_current_name) +
105-
"' not used. Remove the rfl::NoExtraFields processor or add "
106-
"rfl::ExtraFields to avoid this error message."));
106+
std::stringstream stream;
107+
stream << "Value named '" << std::string(_current_name)
108+
<< "' not used. Remove the rfl::NoExtraFields processor or add "
109+
"rfl::ExtraFields to avoid this error message.";
110+
_errors->emplace_back(Error(stream.str()));
107111
}
108112
}
109113
}

0 commit comments

Comments
 (0)