Skip to content

Commit

Permalink
Add google-explicit-constructor check (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau authored Oct 16, 2024
1 parent fc0aa21 commit 86d08eb
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 19 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ cppcoreguidelines-*,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-rvalue-reference-param-not-moved,
google-*,
-google-explicit-constructor,
-google-readability-casting,
-google-readability-todo,
-google-runtime-int,
Expand Down
6 changes: 3 additions & 3 deletions include/ddc/chunk_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ChunkSpan<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy, Memo
class OElementType,
class Allocator,
class = std::enable_if_t<std::is_same_v<typename Allocator::memory_space, MemorySpace>>>
KOKKOS_FUNCTION constexpr ChunkSpan(
KOKKOS_FUNCTION constexpr explicit ChunkSpan(
Chunk<OElementType, discrete_domain_type, Allocator>& other) noexcept
: base_type(other.m_internal_mdspan, other.m_domain)
{
Expand All @@ -174,7 +174,7 @@ class ChunkSpan<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy, Memo
class = std::enable_if_t<std::is_const_v<SFINAEElementType>>,
class Allocator,
class = std::enable_if_t<std::is_same_v<typename Allocator::memory_space, MemorySpace>>>
KOKKOS_FUNCTION constexpr ChunkSpan(
KOKKOS_FUNCTION constexpr explicit ChunkSpan(
Chunk<OElementType, discrete_domain_type, Allocator> const& other) noexcept
: base_type(other.m_internal_mdspan, other.m_domain)
{
Expand All @@ -184,7 +184,7 @@ class ChunkSpan<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy, Memo
* @param other the ChunkSpan to move
*/
template <class OElementType>
KOKKOS_FUNCTION constexpr ChunkSpan(
KOKKOS_FUNCTION constexpr explicit ChunkSpan(
ChunkSpan<OElementType, discrete_domain_type, layout_type, MemorySpace> const&
other) noexcept
: base_type(other.m_internal_mdspan, other.m_domain)
Expand Down
6 changes: 4 additions & 2 deletions include/ddc/detail/tagged_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ template <class ElementType, class Tag>
class TaggedVectorConversionOperators<TaggedVector<ElementType, Tag>>
{
public:
// NOLINTBEGIN(google-explicit-constructor)
KOKKOS_FUNCTION constexpr operator ElementType const&() const noexcept
{
return static_cast<TaggedVector<ElementType, Tag> const*>(this)->m_values[0];
Expand All @@ -241,6 +242,7 @@ class TaggedVectorConversionOperators<TaggedVector<ElementType, Tag>>
{
return static_cast<TaggedVector<ElementType, Tag>*>(this)->m_values[0];
}
// NOLINTEND(google-explicit-constructor)
};

template <class ElementType, class... Tags>
Expand Down Expand Up @@ -269,7 +271,7 @@ class TaggedVector : public TaggedVectorConversionOperators<TaggedVector<Element
KOKKOS_DEFAULTED_FUNCTION constexpr TaggedVector(TaggedVector&&) = default;

template <class... TVectors, class = std::enable_if_t<(is_tagged_vector_v<TVectors> && ...)>>
explicit KOKKOS_FUNCTION constexpr TaggedVector(TVectors const&... delems) noexcept
KOKKOS_FUNCTION constexpr explicit TaggedVector(TVectors const&... delems) noexcept
: m_values {static_cast<ElementType>(take<Tags>(delems...).template get<Tags>())...}
{
}
Expand All @@ -279,7 +281,7 @@ class TaggedVector : public TaggedVectorConversionOperators<TaggedVector<Element
class = std::enable_if_t<(!is_tagged_vector_v<Params> && ...)>,
class = std::enable_if_t<(std::is_convertible_v<Params, ElementType> && ...)>,
class = std::enable_if_t<sizeof...(Params) == sizeof...(Tags)>>
explicit KOKKOS_FUNCTION constexpr TaggedVector(Params const&... params) noexcept
KOKKOS_FUNCTION constexpr explicit TaggedVector(Params const&... params) noexcept
: m_values {static_cast<ElementType>(params)...}
{
}
Expand Down
4 changes: 2 additions & 2 deletions include/ddc/discrete_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DiscreteDomain

/// Construct a DiscreteDomain by copies and merge of domains
template <class... DDoms, class = std::enable_if_t<(is_discrete_domain_v<DDoms> && ...)>>
explicit KOKKOS_FUNCTION constexpr DiscreteDomain(DDoms const&... domains)
KOKKOS_FUNCTION constexpr explicit DiscreteDomain(DDoms const&... domains)
: m_element_begin(domains.front()...)
, m_element_end((domains.front() + domains.extents())...)
{
Expand Down Expand Up @@ -264,7 +264,7 @@ class DiscreteDomain<>

// Construct a DiscreteDomain from a reordered copy of `domain`
template <class... ODDims>
explicit KOKKOS_FUNCTION constexpr DiscreteDomain(
KOKKOS_FUNCTION constexpr explicit DiscreteDomain(
[[maybe_unused]] DiscreteDomain<ODDims...> const& domain)
{
}
Expand Down
4 changes: 2 additions & 2 deletions include/ddc/discrete_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DiscreteElement
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement(DiscreteElement&&) = default;

template <class... DElems, class = std::enable_if_t<(is_discrete_element_v<DElems> && ...)>>
explicit KOKKOS_FUNCTION constexpr DiscreteElement(DElems const&... delems) noexcept
KOKKOS_FUNCTION constexpr explicit DiscreteElement(DElems const&... delems) noexcept
: m_values {take<Tags>(delems...).template uid<Tags>()...}
{
}
Expand All @@ -184,7 +184,7 @@ class DiscreteElement
class = std::enable_if_t<(!is_discrete_element_v<Params> && ...)>,
class = std::enable_if_t<(std::is_integral_v<Params> && ...)>,
class = std::enable_if_t<sizeof...(Params) == sizeof...(Tags)>>
explicit KOKKOS_FUNCTION constexpr DiscreteElement(Params const&... params) noexcept
KOKKOS_FUNCTION constexpr explicit DiscreteElement(Params const&... params) noexcept
: m_values {static_cast<value_type>(params)...}
{
}
Expand Down
6 changes: 4 additions & 2 deletions include/ddc/discrete_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ template <class Tag>
class DiscreteVectorConversionOperators<DiscreteVector<Tag>>
{
public:
// NOLINTBEGIN(google-explicit-constructor)
KOKKOS_FUNCTION constexpr operator DiscreteVectorElement const&() const noexcept
{
return static_cast<DiscreteVector<Tag> const*>(this)->m_values[0];
Expand All @@ -226,6 +227,7 @@ class DiscreteVectorConversionOperators<DiscreteVector<Tag>>
{
return static_cast<DiscreteVector<Tag>*>(this)->m_values[0];
}
// NOLINTEND(google-explicit-constructor)
};

/// Returns a reference to the underlying `std::array`
Expand Down Expand Up @@ -279,7 +281,7 @@ class DiscreteVector : public detail::DiscreteVectorConversionOperators<Discrete
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector(DiscreteVector&&) = default;

template <class... DVects, class = std::enable_if_t<(is_discrete_vector_v<DVects> && ...)>>
explicit KOKKOS_FUNCTION constexpr DiscreteVector(DVects const&... delems) noexcept
KOKKOS_FUNCTION constexpr explicit DiscreteVector(DVects const&... delems) noexcept
: m_values {take<Tags>(delems...).template get<Tags>()...}
{
}
Expand All @@ -289,7 +291,7 @@ class DiscreteVector : public detail::DiscreteVectorConversionOperators<Discrete
class = std::enable_if_t<(!is_discrete_vector_v<Params> && ...)>,
class = std::enable_if_t<(std::is_convertible_v<Params, DiscreteVectorElement> && ...)>,
class = std::enable_if_t<sizeof...(Params) == sizeof...(Tags)>>
explicit KOKKOS_FUNCTION constexpr DiscreteVector(Params const&... params) noexcept
KOKKOS_FUNCTION constexpr explicit DiscreteVector(Params const&... params) noexcept
: m_values {static_cast<DiscreteVectorElement>(params)...}
{
}
Expand Down
2 changes: 1 addition & 1 deletion include/ddc/experimental/single_discretization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SingleDiscretization : SingleDiscretizationBase

using discrete_vector_type = DiscreteVector<DDim>;

Impl(continuous_element_type origin) noexcept : m_point(std::move(origin)) {}
explicit Impl(continuous_element_type origin) noexcept : m_point(std::move(origin)) {}

template <class OriginMemorySpace>
explicit Impl(Impl<DDim, OriginMemorySpace> const& impl) : m_point(impl.m_point)
Expand Down
2 changes: 1 addition & 1 deletion include/ddc/kernels/splines/bsplines_non_uniform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class NonUniformBSplines : detail::NonUniformBSplinesBase
*
* @param breaks The std::initializer_list of the coordinates of break points.
*/
explicit Impl(std::initializer_list<ddc::Coordinate<CDim>> breaks)
Impl(std::initializer_list<ddc::Coordinate<CDim>> breaks)
: Impl(breaks.begin(), breaks.end())
{
}
Expand Down
2 changes: 1 addition & 1 deletion include/ddc/non_uniform_point_sampling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class NonUniformPointSampling : detail::NonUniformPointSamplingBase
Impl() = default;

/// @brief Construct a `NonUniformPointSampling` using a brace-list, i.e. `NonUniformPointSampling mesh({0., 1.})`
explicit Impl(std::initializer_list<continuous_element_type> points)
Impl(std::initializer_list<continuous_element_type> points)
{
std::vector<continuous_element_type> host_points(points.begin(), points.end());
Kokkos::View<continuous_element_type*, Kokkos::HostSpace> const
Expand Down
4 changes: 2 additions & 2 deletions tests/splines/cosine_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ struct CosineEvaluator

public:
template <class Domain>
Evaluator([[maybe_unused]] Domain domain) : m_c0(1.0)
, m_c1(0.0)
explicit Evaluator([[maybe_unused]] Domain domain) : m_c0(1.0)
, m_c1(0.0)
{
}

Expand Down
3 changes: 2 additions & 1 deletion tests/splines/polynomial_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct PolynomialEvaluator

public:
template <class Domain>
Evaluator(Domain domain) : m_xN(std::max(std::abs(rmin(domain)), std::abs(rmax(domain))))
explicit Evaluator(Domain domain)
: m_xN(std::max(std::abs(rmin(domain)), std::abs(rmax(domain))))
{
std::random_device rd;
std::mt19937 gen(rd());
Expand Down
2 changes: 1 addition & 1 deletion tests/splines/spline_error_bounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SplineErrorBounds
}

public:
SplineErrorBounds(Evaluator const& evaluator) : m_evaluator(evaluator) {}
explicit SplineErrorBounds(Evaluator const& evaluator) : m_evaluator(evaluator) {}

double error_bound(double cell_width, int degree)
{
Expand Down

0 comments on commit 86d08eb

Please sign in to comment.