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

Suppress Clang-Tidy warning #4311

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
57e22b9
:rotating_light: suppress warning
nlohmann Mar 15, 2024
b131d28
:rotating_light: fix warning
nlohmann Mar 15, 2024
7b89d3a
:rotating_light: fix warning
nlohmann Mar 15, 2024
cc4d7f1
:rotating_light: fix warning
nlohmann Mar 15, 2024
22d3ee9
:rotating_light: fix warning
nlohmann Mar 15, 2024
91be9e0
:rotating_light: fix warning
nlohmann Mar 15, 2024
8ef2759
:rotating_light: fix warning
nlohmann Mar 26, 2024
414345e
:rotating_light: fix warning
nlohmann Apr 13, 2024
760f54f
:rotating_light: fix warning
nlohmann Apr 14, 2024
e8cfe1f
:rotating_light: fix warning
nlohmann Apr 14, 2024
4b7721c
:rotating_light: fix warning
nlohmann Apr 14, 2024
bb2468a
:rotating_light: fix warning
nlohmann Apr 15, 2024
751b936
:rotating_light: fix warning
nlohmann Apr 15, 2024
3c28221
:rotating_light: fix warning
nlohmann Apr 15, 2024
fd96812
:rotating_light: fix warning
nlohmann Apr 15, 2024
88318f9
:twisted_rightwards_arrows: merge develop
nlohmann Nov 8, 2024
83dc915
:ambulance: fix warning
nlohmann Nov 8, 2024
c4ec5e0
Merge branch 'develop' into clang-tidy
nlohmann Nov 8, 2024
b48e05b
:green_heart: update actions
nlohmann Nov 8, 2024
9240ba4
Merge remote-tracking branch 'origin/clang-tidy' into clang-tidy
nlohmann Nov 8, 2024
ddecb70
:rotating_light: fix warning
nlohmann Nov 8, 2024
078d25e
:rotating_light: fix warning
nlohmann Nov 8, 2024
ad552c4
:rotating_light: fix warning
nlohmann Nov 8, 2024
9561a12
:rotating_light: fix warning
nlohmann Nov 8, 2024
5e9bf55
# Conflicts:
nlohmann Nov 16, 2024
a65d65c
:twisted_rightwards_arrows: merge develop
nlohmann Nov 16, 2024
2e928c3
:twisted_rightwards_arrows: merge develop
nlohmann Nov 17, 2024
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Checks: '*,
-modernize-concat-nested-namespaces,
-modernize-type-traits,
-modernize-use-constraints,
-modernize-use-designated-initializers,
-modernize-use-nodiscard,
-modernize-use-std-numbers,
-modernize-use-trailing-return-type,
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/detail/meta/cpp_future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct static_const
#endif

template<typename T, typename... Args>
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
{
return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
}
Expand Down
6 changes: 3 additions & 3 deletions include/nlohmann/detail/meta/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ struct value_in_range_of_impl1<OfType, T, true>
};

template<typename OfType, typename T>
inline constexpr bool value_in_range_of(T val)
constexpr bool value_in_range_of(T val)
{
return value_in_range_of_impl1<OfType, T>::test(val);
}
Expand All @@ -750,7 +750,7 @@ namespace impl
{

template<typename T>
inline constexpr bool is_c_string()
constexpr bool is_c_string()
{
using TUnExt = typename std::remove_extent<T>::type;
using TUnCVExt = typename std::remove_cv<TUnExt>::type;
Expand Down Expand Up @@ -778,7 +778,7 @@ namespace impl
{

template<typename T>
inline constexpr bool is_transparent()
constexpr bool is_transparent()
{
return is_detected<detect_is_transparent, T>::value;
}
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/detail/output/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ class serializer
@param[in] x unsigned integer number to count its digits
@return number of decimal digits
*/
inline unsigned int count_digits(number_unsigned_t x) noexcept
unsigned int count_digits(number_unsigned_t x) noexcept
{
unsigned int n_digits = 1;
for (;;)
Expand Down Expand Up @@ -952,7 +952,7 @@ class serializer
* absolute values of INT_MIN and INT_MAX are usually not the same. See
* #1708 for details.
*/
inline number_unsigned_t remove_sign(number_integer_t x) noexcept
number_unsigned_t remove_sign(number_integer_t x) noexcept
{
JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)
return static_cast<number_unsigned_t>(-(x + 1)) + 1;
Expand Down
12 changes: 5 additions & 7 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,15 +1212,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief move constructor
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
basic_json(basic_json&& other) noexcept
: json_base_class_t(std::forward<json_base_class_t>(other)),
m_data(std::move(other.m_data))
// check that passed value is valid (has to be done before forwarding)
: json_base_class_t((other.assert_invariant(false), std::forward<json_base_class_t>(other))),
Copy link
Contributor

@gregmarr gregmarr Mar 15, 2024

Choose a reason for hiding this comment

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

Can we just do assert_invariant(false); in the body (assert it in this after moving instead of asserting in other) to avoid this mess?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another possibility for avoiding all these issues is to do std::swap() on m_data and other.m_data in the body.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I am not at all happy with this. I also thought about swapping...

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for asking a question for something that is probably obvious, but which constructor of json_base_class_t is this call valid for? I suppose it is one of the basic_json constructors being used here?

FWIW, it should be completely fine to check the invariants after the initializer list has been evaluated. Is there a possibility to consider rewriting the data move constructor so these assignments don't need to be done at this level?

m_data(std::move(other.m_data))// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)
{
// check that passed value is valid
other.assert_invariant(false);

// invalidate payload
other.m_data.m_type = value_t::null;
other.m_data.m_value = {};
other.m_data.m_type = value_t::null; // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)
other.m_data.m_value = {};// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)

set_parents();
assert_invariant();
Expand Down
24 changes: 11 additions & 13 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3219,7 +3219,7 @@ struct static_const
#endif

template<typename T, typename... Args>
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
{
return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
}
Expand Down Expand Up @@ -4147,7 +4147,7 @@ struct value_in_range_of_impl1<OfType, T, true>
};

template<typename OfType, typename T>
inline constexpr bool value_in_range_of(T val)
constexpr bool value_in_range_of(T val)
{
return value_in_range_of_impl1<OfType, T>::test(val);
}
Expand All @@ -4163,7 +4163,7 @@ namespace impl
{

template<typename T>
inline constexpr bool is_c_string()
constexpr bool is_c_string()
{
using TUnExt = typename std::remove_extent<T>::type;
using TUnCVExt = typename std::remove_cv<TUnExt>::type;
Expand Down Expand Up @@ -4191,7 +4191,7 @@ namespace impl
{

template<typename T>
inline constexpr bool is_transparent()
constexpr bool is_transparent()
{
return is_detected<detect_is_transparent, T>::value;
}
Expand Down Expand Up @@ -18652,7 +18652,7 @@ class serializer
@param[in] x unsigned integer number to count its digits
@return number of decimal digits
*/
inline unsigned int count_digits(number_unsigned_t x) noexcept
unsigned int count_digits(number_unsigned_t x) noexcept
{
unsigned int n_digits = 1;
for (;;)
Expand Down Expand Up @@ -18961,7 +18961,7 @@ class serializer
* absolute values of INT_MIN and INT_MAX are usually not the same. See
* #1708 for details.
*/
inline number_unsigned_t remove_sign(number_integer_t x) noexcept
number_unsigned_t remove_sign(number_integer_t x) noexcept
{
JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)
return static_cast<number_unsigned_t>(-(x + 1)) + 1;
Expand Down Expand Up @@ -20515,15 +20515,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief move constructor
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
basic_json(basic_json&& other) noexcept
: json_base_class_t(std::forward<json_base_class_t>(other)),
m_data(std::move(other.m_data))
// check that passed value is valid (has to be done before forwarding)
: json_base_class_t((other.assert_invariant(false), std::forward<json_base_class_t>(other))),
m_data(std::move(other.m_data))// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)
{
// check that passed value is valid
other.assert_invariant(false);

// invalidate payload
other.m_data.m_type = value_t::null;
other.m_data.m_value = {};
other.m_data.m_type = value_t::null; // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)
other.m_data.m_value = {};// NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)

set_parents();
assert_invariant();
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ TEST_CASE("value conversion")

SECTION("non-const")
{
const json j_const = j;
const json j_const = j; // NOLINT(performance-unnecessary-copy-initialization)
const auto& b = j_const.get_binary();
CHECK(*json(b).m_data.m_value.binary == *j.m_data.m_value.binary);
}
Expand Down
Loading