Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignores some cppcheck warnings #1876

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/nlohmann/detail/input/input_adapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,22 +336,28 @@ class input_adapter
public:
// native support
JSON_HEDLEY_NON_NULL(2)
// cppcheck-suppress noExplicitConstructor
input_adapter(std::FILE* file)
: ia(std::make_shared<file_input_adapter>(file)) {}
/// input adapter for input stream
// cppcheck-suppress noExplicitConstructor
input_adapter(std::istream& i)
: ia(std::make_shared<input_stream_adapter>(i)) {}

/// input adapter for input stream
// cppcheck-suppress noExplicitConstructor
input_adapter(std::istream&& i)
: ia(std::make_shared<input_stream_adapter>(i)) {}

// cppcheck-suppress noExplicitConstructor
input_adapter(const std::wstring& ws)
: ia(std::make_shared<wide_string_input_adapter<std::wstring>>(ws)) {}

// cppcheck-suppress noExplicitConstructor
input_adapter(const std::u16string& ws)
: ia(std::make_shared<wide_string_input_adapter<std::u16string>>(ws)) {}

// cppcheck-suppress noExplicitConstructor
input_adapter(const std::u32string& ws)
: ia(std::make_shared<wide_string_input_adapter<std::u32string>>(ws)) {}

Expand All @@ -374,6 +380,7 @@ class input_adapter
std::is_integral<typename std::remove_pointer<CharT>::type>::value and
sizeof(typename std::remove_pointer<CharT>::type) == 1,
int>::type = 0>
// cppcheck-suppress noExplicitConstructor
input_adapter(CharT b)
: input_adapter(reinterpret_cast<const char*>(b),
std::strlen(reinterpret_cast<const char*>(b))) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the reason why

Expand Down Expand Up @@ -418,6 +425,7 @@ class input_adapter

/// input adapter for array
template<class T, std::size_t N>
// cppcheck-suppress noExplicitConstructor
input_adapter(T (&array)[N])
: input_adapter(std::begin(array), std::end(array)) {}

Expand All @@ -426,6 +434,7 @@ class input_adapter
std::enable_if<not std::is_pointer<ContiguousContainer>::value and
std::is_base_of<std::random_access_iterator_tag, typename iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::value,
int>::type = 0>
// cppcheck-suppress noExplicitConstructor
input_adapter(const ContiguousContainer& c)
: input_adapter(std::begin(c), std::end(c)) {}

Expand Down
4 changes: 4 additions & 0 deletions include/nlohmann/detail/json_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ class json_ref
public:
using value_type = BasicJsonType;

// cppcheck-suppress noExplicitConstructor
json_ref(value_type&& value)
: owned_value(std::move(value)), value_ref(&owned_value), is_rvalue(true)
{}

// cppcheck-suppress noExplicitConstructor
json_ref(const value_type& value)
: value_ref(const_cast<value_type*>(&value)), is_rvalue(false)
{}

// cppcheck-suppress noExplicitConstructor
json_ref(std::initializer_list<json_ref> init)
: owned_value(init), value_ref(&owned_value), is_rvalue(true)
{}

template <
class... Args,
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
// cppcheck-suppress noExplicitConstructor
json_ref(Args && ... args)
: owned_value(std::forward<Args>(args)...), value_ref(&owned_value),
is_rvalue(true) {}
Expand Down
3 changes: 3 additions & 0 deletions include/nlohmann/detail/output/output_adapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_adapter
{
public:
// cppcheck-suppress noExplicitConstructor
output_adapter(std::vector<CharType>& vec)
: oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}

// cppcheck-suppress noExplicitConstructor
output_adapter(std::basic_ostream<CharType>& s)
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}

// cppcheck-suppress noExplicitConstructor
output_adapter(StringType& s)
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}

Expand Down
5 changes: 5 additions & 0 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ class basic_json

@since version 1.0.0
*/
// cppcheck-suppress noExplicitConstructor
basic_json(const value_t v)
: m_type(v), m_value(v)
{
Expand All @@ -1230,6 +1231,7 @@ class basic_json

@since version 1.0.0
*/
// cppcheck-suppress noExplicitConstructor
basic_json(std::nullptr_t = nullptr) noexcept
: basic_json(value_t::null)
{
Expand Down Expand Up @@ -1297,6 +1299,7 @@ class basic_json
typename U = detail::uncvref_t<CompatibleType>,
detail::enable_if_t<
not detail::is_basic_json<U>::value and detail::is_compatible_type<basic_json_t, U>::value, int> = 0>
// cppcheck-suppress noExplicitConstructor
basic_json(CompatibleType && val) noexcept(noexcept(
JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
std::forward<CompatibleType>(val))))
Expand Down Expand Up @@ -1334,6 +1337,7 @@ class basic_json
template <typename BasicJsonType,
detail::enable_if_t<
detail::is_basic_json<BasicJsonType>::value and not std::is_same<basic_json, BasicJsonType>::value, int> = 0>
// cppcheck-suppress noExplicitConstructor
basic_json(const BasicJsonType& val)
{
using other_boolean_t = typename BasicJsonType::boolean_t;
Expand Down Expand Up @@ -1774,6 +1778,7 @@ class basic_json
///////////////////////////////////////

/// @private
// cppcheck-suppress noExplicitConstructor
basic_json(const detail::json_ref<basic_json>& ref)
: basic_json(ref.moved_or_copied())
{}
Expand Down
21 changes: 21 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4199,22 +4199,28 @@ class input_adapter
public:
// native support
JSON_HEDLEY_NON_NULL(2)
// cppcheck-suppress noExplicitConstructor
input_adapter(std::FILE* file)
: ia(std::make_shared<file_input_adapter>(file)) {}
/// input adapter for input stream
// cppcheck-suppress noExplicitConstructor
input_adapter(std::istream& i)
: ia(std::make_shared<input_stream_adapter>(i)) {}

/// input adapter for input stream
// cppcheck-suppress noExplicitConstructor
input_adapter(std::istream&& i)
: ia(std::make_shared<input_stream_adapter>(i)) {}

// cppcheck-suppress noExplicitConstructor
input_adapter(const std::wstring& ws)
: ia(std::make_shared<wide_string_input_adapter<std::wstring>>(ws)) {}

// cppcheck-suppress noExplicitConstructor
input_adapter(const std::u16string& ws)
: ia(std::make_shared<wide_string_input_adapter<std::u16string>>(ws)) {}

// cppcheck-suppress noExplicitConstructor
input_adapter(const std::u32string& ws)
: ia(std::make_shared<wide_string_input_adapter<std::u32string>>(ws)) {}

Expand All @@ -4237,6 +4243,7 @@ class input_adapter
std::is_integral<typename std::remove_pointer<CharT>::type>::value and
sizeof(typename std::remove_pointer<CharT>::type) == 1,
int>::type = 0>
// cppcheck-suppress noExplicitConstructor
input_adapter(CharT b)
: input_adapter(reinterpret_cast<const char*>(b),
std::strlen(reinterpret_cast<const char*>(b))) {}
Expand Down Expand Up @@ -4281,6 +4288,7 @@ class input_adapter

/// input adapter for array
template<class T, std::size_t N>
// cppcheck-suppress noExplicitConstructor
input_adapter(T (&array)[N])
: input_adapter(std::begin(array), std::end(array)) {}

Expand All @@ -4289,6 +4297,7 @@ class input_adapter
std::enable_if<not std::is_pointer<ContiguousContainer>::value and
std::is_base_of<std::random_access_iterator_tag, typename iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::value,
int>::type = 0>
// cppcheck-suppress noExplicitConstructor
input_adapter(const ContiguousContainer& c)
: input_adapter(std::begin(c), std::end(c)) {}

Expand Down Expand Up @@ -11103,21 +11112,25 @@ class json_ref
public:
using value_type = BasicJsonType;

// cppcheck-suppress noExplicitConstructor
json_ref(value_type&& value)
: owned_value(std::move(value)), value_ref(&owned_value), is_rvalue(true)
{}

// cppcheck-suppress noExplicitConstructor
json_ref(const value_type& value)
: value_ref(const_cast<value_type*>(&value)), is_rvalue(false)
{}

// cppcheck-suppress noExplicitConstructor
json_ref(std::initializer_list<json_ref> init)
: owned_value(init), value_ref(&owned_value), is_rvalue(true)
{}

template <
class... Args,
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
// cppcheck-suppress noExplicitConstructor
json_ref(Args && ... args)
: owned_value(std::forward<Args>(args)...), value_ref(&owned_value),
is_rvalue(true) {}
Expand Down Expand Up @@ -11282,12 +11295,15 @@ template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_adapter
{
public:
// cppcheck-suppress noExplicitConstructor
output_adapter(std::vector<CharType>& vec)
: oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}

// cppcheck-suppress noExplicitConstructor
output_adapter(std::basic_ostream<CharType>& s)
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}

// cppcheck-suppress noExplicitConstructor
output_adapter(StringType& s)
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}

Expand Down Expand Up @@ -15749,6 +15765,7 @@ class basic_json

@since version 1.0.0
*/
// cppcheck-suppress noExplicitConstructor
basic_json(const value_t v)
: m_type(v), m_value(v)
{
Expand All @@ -15773,6 +15790,7 @@ class basic_json

@since version 1.0.0
*/
// cppcheck-suppress noExplicitConstructor
basic_json(std::nullptr_t = nullptr) noexcept
: basic_json(value_t::null)
{
Expand Down Expand Up @@ -15840,6 +15858,7 @@ class basic_json
typename U = detail::uncvref_t<CompatibleType>,
detail::enable_if_t<
not detail::is_basic_json<U>::value and detail::is_compatible_type<basic_json_t, U>::value, int> = 0>
// cppcheck-suppress noExplicitConstructor
basic_json(CompatibleType && val) noexcept(noexcept(
JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
std::forward<CompatibleType>(val))))
Expand Down Expand Up @@ -15877,6 +15896,7 @@ class basic_json
template <typename BasicJsonType,
detail::enable_if_t<
detail::is_basic_json<BasicJsonType>::value and not std::is_same<basic_json, BasicJsonType>::value, int> = 0>
// cppcheck-suppress noExplicitConstructor
basic_json(const BasicJsonType& val)
{
using other_boolean_t = typename BasicJsonType::boolean_t;
Expand Down Expand Up @@ -16317,6 +16337,7 @@ class basic_json
///////////////////////////////////////

/// @private
// cppcheck-suppress noExplicitConstructor
basic_json(const detail::json_ref<basic_json>& ref)
: basic_json(ref.moved_or_copied())
{}
Expand Down