Skip to content

Commit adfa961

Browse files
authored
Merge pull request #1280 from nlohmann/feature/linter
Removed linter warnings
2 parents ac38e95 + 6d34d64 commit adfa961

29 files changed

+340
-348
lines changed

include/nlohmann/adl_serializer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ struct adl_serializer
4646
::nlohmann::to_json(j, std::forward<ValueType>(val));
4747
}
4848
};
49-
}
49+
} // namespace nlohmann

include/nlohmann/detail/conversions/from_json.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void from_json(const BasicJsonType& j, std::pair<A1, A2>& p)
299299
}
300300

301301
template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
302-
void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...>)
302+
void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...> /*unused*/)
303303
{
304304
t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...);
305305
}
@@ -358,13 +358,13 @@ struct from_json_fn
358358
return from_json(j, val);
359359
}
360360
};
361-
}
361+
} // namespace detail
362362

363363
/// namespace to hold default `from_json` function
364364
/// to see why this is required:
365365
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
366366
namespace
367367
{
368368
constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
369-
}
370-
}
369+
} // namespace
370+
} // namespace nlohmann

include/nlohmann/detail/conversions/to_chars.hpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ struct diyfp // f * 2^e
4747
{
4848
static constexpr int kPrecision = 64; // = q
4949

50-
uint64_t f;
51-
int e;
50+
uint64_t f = 0;
51+
int e = 0;
5252

53-
constexpr diyfp() noexcept : f(0), e(0) {}
5453
constexpr diyfp(uint64_t f_, int e_) noexcept : f(f_), e(e_) {}
5554

5655
/*!
@@ -62,7 +61,7 @@ struct diyfp // f * 2^e
6261
assert(x.e == y.e);
6362
assert(x.f >= y.f);
6463

65-
return diyfp(x.f - y.f, x.e);
64+
return {x.f - y.f, x.e};
6665
}
6766

6867
/*!
@@ -127,7 +126,7 @@ struct diyfp // f * 2^e
127126

128127
const uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32);
129128

130-
return diyfp(h, x.e + y.e + 64);
129+
return {h, x.e + y.e + 64};
131130
}
132131

133132
/*!
@@ -158,7 +157,7 @@ struct diyfp // f * 2^e
158157
assert(delta >= 0);
159158
assert(((x.f << delta) >> delta) == x.f);
160159

161-
return diyfp(x.f << delta, target_exponent);
160+
return {x.f << delta, target_exponent};
162161
}
163162
};
164163

@@ -461,7 +460,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
461460
assert(e >= -1500);
462461
assert(e <= 1500);
463462
const int f = kAlpha - e - 1;
464-
const int k = (f * 78913) / (1 << 18) + (f > 0);
463+
const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0);
465464

466465
const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
467466
assert(index >= 0);
@@ -609,7 +608,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
609608

610609
const diyfp one(uint64_t{1} << -M_plus.e, M_plus.e);
611610

612-
uint32_t p1 = static_cast<uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
611+
auto p1 = static_cast<uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
613612
uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e
614613

615614
// 1)
@@ -928,7 +927,7 @@ inline char* append_exponent(char* buf, int e)
928927
*buf++ = '+';
929928
}
930929

931-
uint32_t k = static_cast<uint32_t>(e);
930+
auto k = static_cast<uint32_t>(e);
932931
if (k < 10)
933932
{
934933
// Always print at least two digits in the exponent.
@@ -1046,7 +1045,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation.
10461045
@note The result is NOT null-terminated.
10471046
*/
10481047
template <typename FloatType>
1049-
char* to_chars(char* first, char* last, FloatType value)
1048+
char* to_chars(char* first, const char* last, FloatType value)
10501049
{
10511050
static_cast<void>(last); // maybe unused - fix warning
10521051
assert(std::isfinite(value));

include/nlohmann/detail/conversions/to_json.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ void to_json(BasicJsonType& j, const std::pair<Args...>& p)
306306
// for https://github.com/nlohmann/json/pull/1134
307307
template<typename BasicJsonType, typename T,
308308
enable_if_t<std::is_same<T, typename iteration_proxy<typename BasicJsonType::iterator>::iteration_proxy_internal>::value, int> = 0>
309-
void to_json(BasicJsonType& j, T b) noexcept
309+
void to_json(BasicJsonType& j, const T& b)
310310
{
311311
j = {{b.key(), b.value()}};
312312
}
313313

314314
template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
315-
void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...>)
315+
void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
316316
{
317317
j = {std::get<Idx>(t)...};
318318
}
@@ -332,11 +332,11 @@ struct to_json_fn
332332
return to_json(j, std::forward<T>(val));
333333
}
334334
};
335-
}
335+
} // namespace detail
336336

337337
/// namespace to hold default `to_json` function
338338
namespace
339339
{
340340
constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
341-
}
342-
}
341+
} // namespace
342+
} // namespace nlohmann

include/nlohmann/detail/exceptions.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,5 @@ class other_error : public exception
326326
private:
327327
other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
328328
};
329-
}
330-
}
329+
} // namespace detail
330+
} // namespace nlohmann

include/nlohmann/detail/input/binary_reader.hpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,20 @@ class binary_reader
392392

393393
case 0xF9: // Half-Precision Float (two-byte IEEE 754)
394394
{
395-
const int byte1 = get();
395+
const int byte1_raw = get();
396396
if (JSON_UNLIKELY(not unexpect_eof()))
397397
{
398398
return false;
399399
}
400-
const int byte2 = get();
400+
const int byte2_raw = get();
401401
if (JSON_UNLIKELY(not unexpect_eof()))
402402
{
403403
return false;
404404
}
405405

406+
const auto byte1 = static_cast<unsigned char>(byte1_raw);
407+
const auto byte2 = static_cast<unsigned char>(byte2_raw);
408+
406409
// code from RFC 7049, Appendix D, Figure 3:
407410
// As half-precision floating-point numbers were only added
408411
// to IEEE 754 in 2008, today's programming platforms often
@@ -1036,13 +1039,15 @@ class binary_reader
10361039
}
10371040

10381041
if (len != std::size_t(-1))
1042+
{
10391043
for (std::size_t i = 0; i < len; ++i)
10401044
{
10411045
if (JSON_UNLIKELY(not parse_cbor_internal()))
10421046
{
10431047
return false;
10441048
}
10451049
}
1050+
}
10461051
else
10471052
{
10481053
while (get() != 0xFF)
@@ -1693,5 +1698,5 @@ class binary_reader
16931698
/// the SAX parser
16941699
json_sax_t* sax = nullptr;
16951700
};
1696-
}
1697-
}
1701+
} // namespace detail
1702+
} // namespace nlohmann

include/nlohmann/detail/input/input_adapters.hpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class input_stream_adapter : public input_adapter_protocol
7171
// delete because of pointer members
7272
input_stream_adapter(const input_stream_adapter&) = delete;
7373
input_stream_adapter& operator=(input_stream_adapter&) = delete;
74+
input_stream_adapter(input_stream_adapter&&) = delete;
75+
input_stream_adapter& operator=(input_stream_adapter&&) = delete;
7476

7577
// std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
7678
// ensure that std::char_traits<char>::eof() and the character 0xFF do not
@@ -97,6 +99,9 @@ class input_buffer_adapter : public input_adapter_protocol
9799
// delete because of pointer members
98100
input_buffer_adapter(const input_buffer_adapter&) = delete;
99101
input_buffer_adapter& operator=(input_buffer_adapter&) = delete;
102+
input_buffer_adapter(input_buffer_adapter&&) = delete;
103+
input_buffer_adapter& operator=(input_buffer_adapter&&) = delete;
104+
~input_buffer_adapter() override = default;
100105

101106
std::char_traits<char>::int_type get_character() noexcept override
102107
{
@@ -131,7 +136,7 @@ struct wide_string_input_helper
131136
else
132137
{
133138
// get the current character
134-
const int wc = static_cast<int>(str[current_wchar++]);
139+
const auto wc = static_cast<int>(str[current_wchar++]);
135140

136141
// UTF-32 to UTF-8 encoding
137142
if (wc < 0x80)
@@ -186,7 +191,7 @@ struct wide_string_input_helper<WideStringType, 2>
186191
else
187192
{
188193
// get the current character
189-
const int wc = static_cast<int>(str[current_wchar++]);
194+
const auto wc = static_cast<int>(str[current_wchar++]);
190195

191196
// UTF-16 to UTF-8 encoding
192197
if (wc < 0x80)
@@ -211,7 +216,7 @@ struct wide_string_input_helper<WideStringType, 2>
211216
{
212217
if (current_wchar < str.size())
213218
{
214-
const int wc2 = static_cast<int>(str[current_wchar++]);
219+
const auto wc2 = static_cast<int>(str[current_wchar++]);
215220
const int charcode = 0x10000 + (((wc & 0x3FF) << 10) | (wc2 & 0x3FF));
216221
utf8_bytes[0] = 0xf0 | (charcode >> 18);
217222
utf8_bytes[1] = 0x80 | ((charcode >> 12) & 0x3F);
@@ -381,5 +386,5 @@ class input_adapter
381386
/// the actual adapter
382387
input_adapter_t ia = nullptr;
383388
};
384-
}
385-
}
389+
} // namespace detail
390+
} // namespace nlohmann

0 commit comments

Comments
 (0)