Skip to content

Commit 7fdf9ef

Browse files
committed
Added compile warning sign-compare
1 parent 5297efe commit 7fdf9ef

32 files changed

+250
-255
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
**/build
1919
*PVS-Studio*
2020
examples/output
21+
**/tests.suppress
2122

2223
examples/build/cmake/build_llvm.sh
2324
examples/build/cmake/build_llvm

examples/src/container_examples.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ void container_example1()
4747
std::array<unsigned long, 4> array1 {{1, 2, 3, 4}};
4848
json j_array1(array1);
4949

50-
std::set<std::string> set1{"one", "two", "three", "four", "one"};
51-
json j_set1(set1); // only one entry for "one" is used
50+
std::set<std::string> set1{"one", "two", "three", "four"};
51+
json j_set1(set1);
5252
std::cout << j_set1 << std::endl;
5353
// ["four", "one", "three", "two"]
5454

55-
std::unordered_set<std::string> uset1{"one", "two", "three", "four", "one"};
56-
json j_uset1(uset1); // only one entry for "one" is used
55+
std::unordered_set<std::string> uset1{"one", "two", "three", "four"};
56+
json j_uset1(uset1);
5757
std::cout << j_uset1 << std::endl;
5858
// maybe ["two", "three", "four", "one"]
5959

include/jsoncons/detail/write_number.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ namespace detail {
312312
return false;
313313
}
314314
}
315-
dump_buffer(buffer, length, decimal_point, result);
315+
dump_buffer(buffer, static_cast<std::size_t>(length), decimal_point, result);
316316
return true;
317317
}
318318

include/jsoncons/json_container_types.hpp

+22-18
Original file line numberDiff line numberDiff line change
@@ -565,21 +565,23 @@ namespace jsoncons {
565565
{
566566
}
567567

568-
json_object& operator=(const json_object& val)
569-
{
570-
allocator_holder<allocator_type>::operator=(val.get_allocator());
571-
members_ = val.members_;
572-
}
573-
574568
json_object(json_object&& val)
575569
: allocator_holder<allocator_type>(val.get_allocator()),
576570
members_(std::move(val.members_))
577571
{
578572
}
579573

574+
json_object& operator=(const json_object& val)
575+
{
576+
allocator_holder<allocator_type>::operator=(val.get_allocator());
577+
members_ = val.members_;
578+
return *this;
579+
}
580+
580581
json_object& operator=(json_object&& val)
581582
{
582583
val.swap(*this);
584+
return *this;
583585
}
584586

585587
json_object(const json_object& val, const allocator_type& alloc)
@@ -1265,25 +1267,13 @@ namespace jsoncons {
12651267
{
12661268
}
12671269

1268-
json_object& operator=(const json_object& val)
1269-
{
1270-
allocator_holder<allocator_type>::operator=(val.get_allocator());
1271-
members_ = val.members_;
1272-
index_ = val.index_;
1273-
}
1274-
12751270
json_object(json_object&& val)
12761271
: allocator_holder<allocator_type>(val.get_allocator()),
12771272
members_(std::move(val.members_)),
12781273
index_(std::move(val.index_))
12791274
{
12801275
}
12811276

1282-
json_object& operator=(json_object&& val)
1283-
{
1284-
val.swap(*this);
1285-
}
1286-
12871277
json_object(const json_object& val, const allocator_type& alloc)
12881278
: allocator_holder<allocator_type>(alloc),
12891279
members_(val.members_,key_value_allocator_type(alloc)),
@@ -1390,6 +1380,20 @@ namespace jsoncons {
13901380
destroy();
13911381
}
13921382

1383+
json_object& operator=(json_object&& val)
1384+
{
1385+
val.swap(*this);
1386+
return *this;
1387+
}
1388+
1389+
json_object& operator=(const json_object& val)
1390+
{
1391+
allocator_holder<allocator_type>::operator=(val.get_allocator());
1392+
members_ = val.members_;
1393+
index_ = val.index_;
1394+
return *this;
1395+
}
1396+
13931397
void swap(json_object& val) noexcept
13941398
{
13951399
members_.swap(val.members_);

include/jsoncons/json_parser.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ class basic_json_parser : public ser_context
134134
using char_allocator_type = typename std::allocator_traits<temp_allocator_type>:: template rebind_alloc<CharT>;
135135
using parse_state_allocator_type = typename std::allocator_traits<temp_allocator_type>:: template rebind_alloc<json_parse_state>;
136136

137-
static constexpr size_t initial_string_buffer_capacity_ = 1024;
138-
static constexpr int default_initial_stack_capacity_ = 100;
137+
static constexpr std::size_t initial_string_buffer_capacity_ = 1024;
138+
static constexpr std::size_t default_initial_stack_capacity_ = 100;
139139

140140
basic_json_decode_options<CharT> options_;
141141

include/jsoncons/uri.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace jsoncons {
114114
// if the URI is not opaque and the path is not already prefixed
115115
// with a '/', add one.
116116
path_.first = uri_.length();
117-
if (!host.empty() && (!path.empty() && path.front() != '/'))
117+
if (!host.empty() && (path.front() != '/'))
118118
{
119119
uri_.push_back('/');
120120
}

include/jsoncons_ext/cbor/cbor_encoder.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
149149
ec = cbor_errc::max_nesting_depth_exceeded;
150150
return false;
151151
}
152-
stack_.push_back(stack_item(cbor_container_type::indefinite_length_object));
152+
stack_.emplace_back(cbor_container_type::indefinite_length_object);
153153

154154
sink_.push_back(0xbf);
155155
return true;
@@ -162,7 +162,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
162162
ec = cbor_errc::max_nesting_depth_exceeded;
163163
return false;
164164
}
165-
stack_.push_back(stack_item(cbor_container_type::object, length));
165+
stack_.emplace_back(cbor_container_type::object, length);
166166

167167
if (length <= 0x17)
168168
{
@@ -237,7 +237,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
237237
ec = cbor_errc::max_nesting_depth_exceeded;
238238
return false;
239239
}
240-
stack_.push_back(stack_item(cbor_container_type::indefinite_length_array));
240+
stack_.emplace_back(cbor_container_type::indefinite_length_array);
241241
sink_.push_back(0x9f);
242242
return true;
243243
}
@@ -249,7 +249,7 @@ class basic_cbor_encoder final : public basic_json_visitor<char>
249249
ec = cbor_errc::max_nesting_depth_exceeded;
250250
return false;
251251
}
252-
stack_.push_back(stack_item(cbor_container_type::array, length));
252+
stack_.emplace_back(cbor_container_type::array, length);
253253
if (length <= 0x17)
254254
{
255255
jsoncons::detail::native_to_big(static_cast<uint8_t>(0x80 + length),

include/jsoncons_ext/cbor/cbor_parser.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ class basic_cbor_parser : public ser_context
712712
{
713713
return 0;
714714
}
715-
std::size_t len = (std::size_t)u;
715+
std::size_t len = static_cast<std::size_t>(u);
716716
if (len != u)
717717
{
718718
ec = cbor_errc::number_too_large;

include/jsoncons_ext/csv/csv_encoder.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,15 @@ class basic_csv_encoder final : public basic_json_visitor<CharT>
333333
buffered_line_[string_type(name)] = std::basic_string<CharT>();
334334
if (stack_[0].count_ == 0 && options_.column_names().size() == 0)
335335
{
336-
strings_buffer_.push_back(string_type(name));
336+
strings_buffer_.emplace_back(name);
337337
}
338338
break;
339339
}
340340
case stack_item_kind::column_mapping:
341341
{
342342
if (strings_buffer_.empty())
343343
{
344-
strings_buffer_.push_back(string_type(name));
344+
strings_buffer_.emplace_back(name);
345345
}
346346
else
347347
{

include/jsoncons_ext/jsonpath/json_query.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ namespace jsoncons { namespace jsonpath {
918918
{
919919
std::size_t selector_id = 0;
920920

921-
string_type function_name;
922921
string_type buffer;
923922
int64_t json_text_level = 0;
924923
uint32_t cp = 0;

include/jsoncons_ext/jsonschema/schema_keywords.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ namespace jsonschema {
846846
if (it != sch.object_range().end())
847847
{
848848
for (const auto& prop : it->value().object_range())
849-
pattern_properties_.push_back(
849+
pattern_properties_.emplace_back(
850850
std::make_pair(
851851
std::regex(prop.key(), std::regex::ECMAScript),
852852
builder->build(prop.value(), uris, {prop.key()})));
@@ -1141,7 +1141,7 @@ namespace jsonschema {
11411141
else
11421142
{
11431143
item_validator = *item;
1144-
item++;
1144+
++item;
11451145
}
11461146

11471147
if (!item_validator)

include/jsoncons_ext/jsonschema/subschema.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ namespace jsonschema {
309309
{
310310
uri_wrapper relative(id);
311311
uri_wrapper new_uri = relative.resolve(new_uris.back());
312-
new_uris.push_back(new_uri.string());
312+
new_uris.emplace_back(new_uri.string());
313313
}
314314
}
315315
}

include/jsoncons_ext/msgpack/msgpack_encoder.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace msgpack {
121121
ec = msgpack_errc::max_nesting_depth_exceeded;
122122
return false;
123123
}
124-
stack_.push_back(stack_item(msgpack_container_type::object, length));
124+
stack_.emplace_back(msgpack_container_type::object, length);
125125

126126
if (length <= 15)
127127
{
@@ -180,7 +180,7 @@ namespace msgpack {
180180
ec = msgpack_errc::max_nesting_depth_exceeded;
181181
return false;
182182
}
183-
stack_.push_back(stack_item(msgpack_container_type::array, length));
183+
stack_.emplace_back(msgpack_container_type::array, length);
184184
if (length <= 15)
185185
{
186186
// fixarray

include/jsoncons_ext/ubjson/ubjson_encoder.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class basic_ubjson_encoder final : public basic_json_visitor<char>
122122
ec = ubjson_errc::max_nesting_depth_exceeded;
123123
return false;
124124
}
125-
stack_.push_back(stack_item(ubjson_container_type::indefinite_length_object));
125+
stack_.emplace_back(ubjson_container_type::indefinite_length_object);
126126
sink_.push_back(jsoncons::ubjson::detail::ubjson_format::start_object_marker);
127127

128128
return true;
@@ -135,7 +135,7 @@ class basic_ubjson_encoder final : public basic_json_visitor<char>
135135
ec = ubjson_errc::max_nesting_depth_exceeded;
136136
return false;
137137
}
138-
stack_.push_back(stack_item(ubjson_container_type::object, length));
138+
stack_.emplace_back(ubjson_container_type::object, length);
139139
sink_.push_back(jsoncons::ubjson::detail::ubjson_format::start_object_marker);
140140
sink_.push_back(jsoncons::ubjson::detail::ubjson_format::count_marker);
141141
put_length(length);
@@ -177,7 +177,7 @@ class basic_ubjson_encoder final : public basic_json_visitor<char>
177177
ec = ubjson_errc::max_nesting_depth_exceeded;
178178
return false;
179179
}
180-
stack_.push_back(stack_item(ubjson_container_type::indefinite_length_array));
180+
stack_.emplace_back(ubjson_container_type::indefinite_length_array);
181181
sink_.push_back(jsoncons::ubjson::detail::ubjson_format::start_array_marker);
182182

183183
return true;
@@ -190,7 +190,7 @@ class basic_ubjson_encoder final : public basic_json_visitor<char>
190190
ec = ubjson_errc::max_nesting_depth_exceeded;
191191
return false;
192192
}
193-
stack_.push_back(stack_item(ubjson_container_type::array, length));
193+
stack_.emplace_back(ubjson_container_type::array, length);
194194
sink_.push_back(jsoncons::ubjson::detail::ubjson_format::start_array_marker);
195195
sink_.push_back(jsoncons::ubjson::detail::ubjson_format::count_marker);
196196
put_length(length);

include/jsoncons_ext/ubjson/ubjson_parser.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ class basic_ubjson_parser : public ser_context
788788
int32_t val = jsoncons::detail::big_to_native<int32_t>(buf, sizeof(buf));
789789
if (val >= 0)
790790
{
791-
length = val;
791+
length = static_cast<std::size_t>(val);
792792
}
793793
else
794794
{

tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_
179179
message(STATUS Version " ${CMAKE_CXX_COMPILER_VERSION}")
180180
# older GCC versions don't support
181181
target_compile_options(unit_tests PRIVATE
182-
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall -Wextra -Wcast-align -Wcast-qual -Wimplicit-fallthrough -pedantic>
182+
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall -Wextra -Wcast-align -Wcast-qual -Wimplicit-fallthrough -Wsign-compare -pedantic>
183183
)
184184
endif()
185185

tests/bson/src/bson_test_suite.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace
1717
std::vector<char> read_bytes(const std::string& filename)
1818
{
1919
std::vector<char> bytes;
20-
std::string in_file = "./bson/input/test34.bson";
2120
std::ifstream is(filename, std::ifstream::binary);
2221
REQUIRE(is);
2322
is.seekg (0, is.end);

0 commit comments

Comments
 (0)