refactor: workarounds for clang-tidy-18

This commit is contained in:
Mateusz Pusz
2024-05-08 14:46:04 +02:00
parent 23ab3ecef4
commit 54d144d112
9 changed files with 21 additions and 4 deletions

View File

@ -69,7 +69,7 @@ MP_UNITS_EXPORT struct ratio {
std::intmax_t num;
std::intmax_t den;
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters, google-explicit-constructor, hicpp-explicit-conversions)
MP_UNITS_CONSTEVAL explicit(false) ratio(std::intmax_t n, std::intmax_t d = 1) : num{n}, den{d}
{
gsl_Expects(den != 0);

View File

@ -63,6 +63,7 @@ struct basic_fixed_string {
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) basic_fixed_string(const CharT (&txt)[N + 1]) noexcept
{
gsl_Expects(txt[N] == CharT{});

View File

@ -136,6 +136,7 @@ template<typename T>
struct convert_explicitly {
using value_type = T;
T value;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) convert_explicitly(T v) noexcept(std::is_nothrow_constructible_v<T>) : value(std::move(v))
{
}
@ -145,6 +146,7 @@ template<typename T>
struct convert_implicitly {
using value_type = T;
T value;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) convert_implicitly(T v) noexcept(std::is_nothrow_constructible_v<T>) : value(std::move(v))
{
}

View File

@ -152,6 +152,7 @@ public:
}
template<detail::QuantityConvertibleTo<quantity> Q>
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(!std::convertible_to<typename Q::rep, Rep>) quantity(const Q& q) :
numerical_value_is_an_implementation_detail_(
detail::sudo_cast<quantity>(q).numerical_value_is_an_implementation_detail_)
@ -163,6 +164,7 @@ public:
quantity<quantity_like_traits<Q>::reference, typename quantity_like_traits<Q>::rep>, quantity>
constexpr explicit(is_specialization_of<decltype(quantity_like_traits<Q>::to_numerical_value(std::declval<Q>())),
convert_explicitly> ||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
!std::convertible_to<typename quantity_like_traits<Q>::rep, Rep>) quantity(const Q& q) :
quantity(
::mp_units::quantity{quantity_like_traits<Q>::to_numerical_value(q).value, quantity_like_traits<Q>::reference})

View File

@ -188,6 +188,7 @@ public:
template<QuantityPointOf<absolute_point_origin> QP>
requires std::constructible_from<quantity_type, typename QP::quantity_type>
// TODO add perfect forwarding
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(!std::convertible_to<typename QP::quantity_type, quantity_type>) quantity_point(const QP& qp) :
quantity_from_origin_is_an_implementation_detail_([&] {
if constexpr (point_origin == QP::point_origin)
@ -208,6 +209,7 @@ public:
convert_explicitly> ||
!std::convertible_to<
quantity<quantity_point_like_traits<QP>::reference, typename quantity_point_like_traits<QP>::rep>, quantity_type>)
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
quantity_point(const QP& qp) :
quantity_from_origin_is_an_implementation_detail_(quantity_point_like_traits<QP>::to_quantity(qp).value)
{
@ -292,7 +294,7 @@ public:
convert_explicitly> ||
!std::convertible_to<quantity_type, quantity<quantity_point_like_traits<QP>::reference,
typename quantity_point_like_traits<QP>::rep>>) constexpr
// NOLINTNEXTLINE(*-explicit-conversions, google-explicit-constructor)
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
operator QP_() const& noexcept(
noexcept(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_is_an_implementation_detail_)) &&
std::is_nothrow_copy_constructible_v<rep>)
@ -310,7 +312,7 @@ public:
convert_explicitly> ||
!std::convertible_to<quantity_type, quantity<quantity_point_like_traits<QP>::reference,
typename quantity_point_like_traits<QP>::rep>>) constexpr
// NOLINTNEXTLINE(*-explicit-conversions, google-explicit-constructor)
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
operator QP_() && noexcept(
noexcept(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_is_an_implementation_detail_)) &&
std::is_nothrow_move_constructible_v<rep>)

View File

@ -189,10 +189,12 @@ template<typename Rep, Reference R>
template<Reference R, typename Rep>
requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(R{}).character>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
constexpr auto operator*(R, Rep&&) = delete;
template<Reference R, typename Rep>
requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(R{}).character>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
constexpr auto operator/(R, Rep&&) = delete;
template<typename Q, Reference R>
@ -213,10 +215,12 @@ template<typename Q, Reference R>
template<Reference R, typename Q>
requires Quantity<std::remove_cvref_t<Q>>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
constexpr auto operator*(R, Q&& q) = delete;
template<Reference R, typename Q>
requires Quantity<std::remove_cvref_t<Q>>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
constexpr auto operator/(R, Q&& q) = delete;
[[nodiscard]] consteval AssociatedUnit auto common_reference(AssociatedUnit auto u1, AssociatedUnit auto u2,

View File

@ -89,12 +89,13 @@ struct symbol_text {
fixed_u8string<N> unicode_;
fixed_string<M> ascii_;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) symbol_text(char ch) : unicode_(static_cast<char8_t>(ch)), ascii_(ch)
{
gsl_Expects(detail::is_basic_literal_character_set_char(ch));
}
// NOLINTNEXTLINE(*-avoid-c-arrays)
// NOLINTNEXTLINE(*-avoid-c-arrays, google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) symbol_text(const char (&txt)[N + 1]) :
unicode_(detail::to_u8string(basic_fixed_string{txt})), ascii_(txt)
{
@ -102,6 +103,7 @@ struct symbol_text {
gsl_Expects(detail::is_basic_literal_character_set(txt));
}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) symbol_text(const fixed_string<N>& txt) : unicode_(detail::to_u8string(txt)), ascii_(txt)
{
gsl_Expects(detail::is_basic_literal_character_set(txt.data_));

View File

@ -43,8 +43,10 @@ public:
using value_type = T;
min_impl() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) min_impl(T v) noexcept : value_(v) {}
template<typename U>
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) min_impl(min_impl<U> i) noexcept : value_(static_cast<T>(static_cast<U>(i)))
{
}

View File

@ -264,7 +264,9 @@ struct derived_quantity : quantity<Q::reference, Rep> {
using R = quantity<reference, Rep>;
derived_quantity() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(!std::is_trivial_v<Rep>) derived_quantity(const R& t) : R(t) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(!std::is_trivial_v<Rep>) derived_quantity(R&& t) : R(std::move(t)) {}
constexpr derived_quantity& operator=(const R& t)