From 6d9758d8256ecf90b4bbb100bfc292782199766c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= <foss@grueninger.de> Date: Sat, 30 Nov 2024 22:56:12 +0100 Subject: [PATCH] Make constructors with one non-scalar argument explicit. Found by Cppcheck (noExplicitConstructor). --- dumux/discretization/box/boxgeometryhelper.hh | 6 +++--- .../facecentered/diamond/geometryhelper.hh | 2 +- dumux/geometry/boundingboxtree.hh | 2 +- dumux/geometry/distancefield.hh | 2 +- dumux/geometry/geometricentityset.hh | 6 +++--- .../fluidmatrixinteractions/2p/materiallaw.hh | 6 +++--- .../fluidmatrixinteraction.hh | 16 ++++++++-------- .../mp/mplinearmaterial.hh | 2 +- .../porenetwork/pore/2p/multishapelocalrules.hh | 6 +++--- .../porenetwork/pore/2p/singleshapelocalrules.hh | 6 +++--- dumux/material/fluidstates/compositional.hh | 2 +- dumux/material/fluidstates/immiscible.hh | 2 +- .../material/fluidstates/isothermalimmiscible.hh | 2 +- dumux/material/fluidstates/pressureoverlay.hh | 2 +- dumux/material/fluidstates/saturationoverlay.hh | 2 +- dumux/material/fluidstates/temperatureoverlay.hh | 2 +- .../porenetwork/test_throattransmissibility.cc | 2 +- 17 files changed, 34 insertions(+), 34 deletions(-) diff --git a/dumux/discretization/box/boxgeometryhelper.hh b/dumux/discretization/box/boxgeometryhelper.hh index de996db8a2..0549c4152d 100644 --- a/dumux/discretization/box/boxgeometryhelper.hh +++ b/dumux/discretization/box/boxgeometryhelper.hh @@ -274,7 +274,7 @@ private: static constexpr int dim = 1; public: - BoxGeometryHelper(const typename Element::Geometry& geometry) + explicit BoxGeometryHelper(const typename Element::Geometry& geometry) : geo_(geometry) {} @@ -349,7 +349,7 @@ class BoxGeometryHelper<GridView, 2, ScvType, ScvfType> static constexpr auto dimWorld = GridView::dimensionworld; public: - BoxGeometryHelper(const typename Element::Geometry& geometry) + explicit BoxGeometryHelper(const typename Element::Geometry& geometry) : geo_(geometry) {} @@ -485,7 +485,7 @@ class BoxGeometryHelper<GridView, 3, ScvType, ScvfType> static constexpr auto dimWorld = GridView::dimensionworld; public: - BoxGeometryHelper(const typename Element::Geometry& geometry) + explicit BoxGeometryHelper(const typename Element::Geometry& geometry) : geo_(geometry) {} diff --git a/dumux/discretization/facecentered/diamond/geometryhelper.hh b/dumux/discretization/facecentered/diamond/geometryhelper.hh index 895ba54cb7..6601b9cd48 100644 --- a/dumux/discretization/facecentered/diamond/geometryhelper.hh +++ b/dumux/discretization/facecentered/diamond/geometryhelper.hh @@ -267,7 +267,7 @@ class DiamondGeometryHelper using GlobalPosition = typename Dune::FieldVector<ctype, GridView::dimensionworld>; public: - DiamondGeometryHelper(const typename Element::Geometry& geo) + explicit DiamondGeometryHelper(const typename Element::Geometry& geo) : geo_(geo) {} diff --git a/dumux/geometry/boundingboxtree.hh b/dumux/geometry/boundingboxtree.hh index 8d54d3d32c..5d56630feb 100644 --- a/dumux/geometry/boundingboxtree.hh +++ b/dumux/geometry/boundingboxtree.hh @@ -87,7 +87,7 @@ public: BoundingBoxTree() = default; //! Constructor with gridView - BoundingBoxTree(std::shared_ptr<const GeometricEntitySet> set) + explicit BoundingBoxTree(std::shared_ptr<const GeometricEntitySet> set) { build(set); } //! Build up bounding box tree for a grid with leafGridView diff --git a/dumux/geometry/distancefield.hh b/dumux/geometry/distancefield.hh index 7102df28fe..ec5df4e93e 100644 --- a/dumux/geometry/distancefield.hh +++ b/dumux/geometry/distancefield.hh @@ -58,7 +58,7 @@ public: * \brief The constructor. * \param geometries A vector of geometries describing the boundaries of the spatial domain. */ - AABBDistanceField(const std::vector<Geometry>& geometries) + explicit AABBDistanceField(const std::vector<Geometry>& geometries) : tree_(std::make_unique<AABBTree>(std::make_shared<GeoSet>(geometries))) { std::vector<PointGeometry> points; diff --git a/dumux/geometry/geometricentityset.hh b/dumux/geometry/geometricentityset.hh index 78b308f7ac..2d073537d9 100644 --- a/dumux/geometry/geometricentityset.hh +++ b/dumux/geometry/geometricentityset.hh @@ -39,7 +39,7 @@ class GridViewGeometricEntitySet public: using Entity = typename GridView::template Codim<codim>::Entity; - GridViewGeometricEntitySet(const GridView& gridView) + explicit GridViewGeometricEntitySet(const GridView& gridView) : GridViewGeometricEntitySet(gridView, Mapper(gridView, Dune::mcmgLayout(Dune::Codim<codim>()))) {} @@ -177,7 +177,7 @@ public: /*! * \brief Constructor for a vector of geometries */ - GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries) + explicit GeometriesEntitySet(const std::vector<typename Entity::Geometry>& geometries) { std::size_t index = 0; for (auto&& g : geometries) @@ -187,7 +187,7 @@ public: /*! * \brief Constructor for a vector of geometries */ - GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries) + explicit GeometriesEntitySet(std::vector<typename Entity::Geometry>&& geometries) { std::size_t index = 0; for (auto&& g : geometries) diff --git a/dumux/material/fluidmatrixinteractions/2p/materiallaw.hh b/dumux/material/fluidmatrixinteractions/2p/materiallaw.hh index 74b9243ab4..8c8251663f 100644 --- a/dumux/material/fluidmatrixinteractions/2p/materiallaw.hh +++ b/dumux/material/fluidmatrixinteractions/2p/materiallaw.hh @@ -87,9 +87,9 @@ public: * \brief Construct from parameter structs * \note More efficient constructor but you need to ensure all parameters are initialized */ - TwoPMaterialLaw(const BasicParams& baseParams, - const EffToAbsParams& effToAbsParams = {}, - const RegularizationParams& regParams = {}) + explicit TwoPMaterialLaw(const BasicParams& baseParams, + const EffToAbsParams& effToAbsParams = {}, + const RegularizationParams& regParams = {}) : basicParams_(baseParams) , effToAbsParams_(effToAbsParams) { diff --git a/dumux/material/fluidmatrixinteractions/fluidmatrixinteraction.hh b/dumux/material/fluidmatrixinteractions/fluidmatrixinteraction.hh index ed04dafe06..e20ea66456 100644 --- a/dumux/material/fluidmatrixinteractions/fluidmatrixinteraction.hh +++ b/dumux/material/fluidmatrixinteractions/fluidmatrixinteraction.hh @@ -26,7 +26,7 @@ namespace Dumux { template<class... Laws> struct FluidMatrixInteraction : public Laws... { - FluidMatrixInteraction(Laws&&... laws) : Laws(std::forward<Laws>(laws))... {} + explicit FluidMatrixInteraction(Laws&&... laws) : Laws(std::forward<Laws>(laws))... {} }; /*! @@ -69,7 +69,7 @@ public: using PcKrSwType = T; - PcKrSw(T&& impl) : impl_(std::forward<T>(impl)) {} + explicit PcKrSw(T&& impl) : impl_(std::forward<T>(impl)) {} Scalar pc(const Scalar sw) const { return impl_.pc(sw); } Scalar dpc_dsw(const Scalar sw) const { return impl_.dpc_dsw(sw); } @@ -107,7 +107,7 @@ class MultiPhasePcKrSw public: using Scalar = typename std::decay_t<T>::Scalar; - MultiPhasePcKrSw(T&& impl) : impl_(std::forward<T>(impl)) {} + explicit MultiPhasePcKrSw(T&& impl) : impl_(std::forward<T>(impl)) {} template<class FS> auto capillaryPressures(const FS& fs, int wp) const { return impl_.capillaryPressures(fs, wp); } @@ -141,7 +141,7 @@ struct ThreePhasePcKrSw using PcKrSwType = T; - ThreePhasePcKrSw(T&& impl) : impl_(std::forward<T>(impl)) {} + explicit ThreePhasePcKrSw(T&& impl) : impl_(std::forward<T>(impl)) {} Scalar pcgw(const Scalar sw, const Scalar sn) const { return impl_.pcgw(sw, sn); } Scalar pcnw(const Scalar sw, const Scalar sn) const { return impl_.pcnw(sw, sn); } @@ -176,7 +176,7 @@ template<class T> class WettingNonwettingInterfacialAreaPcSw { public: - WettingNonwettingInterfacialAreaPcSw(T&& impl) : impl_(std::forward<T>(impl)) {} + explicit WettingNonwettingInterfacialAreaPcSw(T&& impl) : impl_(std::forward<T>(impl)) {} const T& wettingNonwettingInterface() const { return impl_; } private: T impl_; @@ -199,7 +199,7 @@ template<class T> class WettingSolidInterfacialAreaPcSw { public: - WettingSolidInterfacialAreaPcSw(T&& impl) : impl_(std::forward<T>(impl)) {} + explicit WettingSolidInterfacialAreaPcSw(T&& impl) : impl_(std::forward<T>(impl)) {} const T& wettingSolidInterface() const { return impl_; } private: T impl_; @@ -222,7 +222,7 @@ template<class T> class NonwettingSolidInterfacialAreaPcSw { public: - NonwettingSolidInterfacialAreaPcSw(T&& impl) : impl_(std::forward<T>(impl)) {} + explicit NonwettingSolidInterfacialAreaPcSw(T&& impl) : impl_(std::forward<T>(impl)) {} const T& nonwettingSolidInterface() const { return impl_; } private: T impl_; @@ -248,7 +248,7 @@ class Adsorption public: using value_type = T; - Adsorption(T&& impl) : impl_(std::forward<T>(impl)) {} + explicit Adsorption(T&& impl) : impl_(std::forward<T>(impl)) {} const T& adsorptionModel() const { return impl_; } private: T impl_; diff --git a/dumux/material/fluidmatrixinteractions/mp/mplinearmaterial.hh b/dumux/material/fluidmatrixinteractions/mp/mplinearmaterial.hh index c4406ce25a..97353d01cc 100644 --- a/dumux/material/fluidmatrixinteractions/mp/mplinearmaterial.hh +++ b/dumux/material/fluidmatrixinteractions/mp/mplinearmaterial.hh @@ -50,7 +50,7 @@ public: using BasicParams = Params; using Scalar = S; - MPLinearMaterial(const BasicParams& basicParams) + explicit MPLinearMaterial(const BasicParams& basicParams) : basicParams_(basicParams) {} diff --git a/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/multishapelocalrules.hh b/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/multishapelocalrules.hh index eba5129f6e..f539dd07d5 100644 --- a/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/multishapelocalrules.hh +++ b/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/multishapelocalrules.hh @@ -98,9 +98,9 @@ public: static constexpr int numFluidPhases() { return 2; } - MultiShapeTwoPLocalRules(const BasicParams& baseParams, - //const RegularizationParams& regParams = {}, TODO - const std::string& paramGroup = "") + explicit MultiShapeTwoPLocalRules(const BasicParams& baseParams, + //const RegularizationParams& regParams = {}, TODO + const std::string& paramGroup = "") { shape_ = baseParams.poreShape(); switch (shape_) diff --git a/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/singleshapelocalrules.hh b/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/singleshapelocalrules.hh index 5f5c3ae9f7..9cf2d1757f 100644 --- a/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/singleshapelocalrules.hh +++ b/dumux/material/fluidmatrixinteractions/porenetwork/pore/2p/singleshapelocalrules.hh @@ -66,9 +66,9 @@ public: * \brief Construct from parameter structs * \note More efficient constructor but you need to ensure all parameters are initialized */ - SingleShapeTwoPLocalRules(const BasicParams& baseParams = {}, - const RegularizationParams& regParams = {}, - const std::string& paramGroup = "") + explicit SingleShapeTwoPLocalRules(const BasicParams& baseParams = {}, + const RegularizationParams& regParams = {}, + const std::string& paramGroup = "") : basicParams_(baseParams) { diff --git a/dumux/material/fluidstates/compositional.hh b/dumux/material/fluidstates/compositional.hh index 93d4c100ab..6dd97c14c8 100644 --- a/dumux/material/fluidstates/compositional.hh +++ b/dumux/material/fluidstates/compositional.hh @@ -45,7 +45,7 @@ public: //! copy constructor from arbitrary fluid state template <class FluidState, typename std::enable_if_t<!std::is_same<FluidState, CompositionalFluidState>::value, int> = 0> - CompositionalFluidState(const FluidState &fs) + explicit CompositionalFluidState(const FluidState &fs) { assign(fs); } // copy and move constructor / assignment operator diff --git a/dumux/material/fluidstates/immiscible.hh b/dumux/material/fluidstates/immiscible.hh index 4402c64dd6..9d276f3b72 100644 --- a/dumux/material/fluidstates/immiscible.hh +++ b/dumux/material/fluidstates/immiscible.hh @@ -40,7 +40,7 @@ public: //! copy constructor from arbitrary fluid state template <class FluidState, typename std::enable_if_t<!std::is_same<FluidState, ImmiscibleFluidState>::value, int> = 0> - ImmiscibleFluidState(const FluidState &fs) + explicit ImmiscibleFluidState(const FluidState &fs) { assign(fs); } // copy and move constructor / assignment operator diff --git a/dumux/material/fluidstates/isothermalimmiscible.hh b/dumux/material/fluidstates/isothermalimmiscible.hh index c4b4bcec63..e0b22cfa37 100644 --- a/dumux/material/fluidstates/isothermalimmiscible.hh +++ b/dumux/material/fluidstates/isothermalimmiscible.hh @@ -40,7 +40,7 @@ public: //! copy constructor from arbitrary fluid state template <class FluidState, typename std::enable_if_t<!std::is_same<FluidState, IsothermalImmiscibleFluidState>::value, int> = 0> - IsothermalImmiscibleFluidState(const FluidState &fs) + explicit IsothermalImmiscibleFluidState(const FluidState &fs) { assign(fs); } // copy and move constructor / assignment operator diff --git a/dumux/material/fluidstates/pressureoverlay.hh b/dumux/material/fluidstates/pressureoverlay.hh index 0dc6251d4f..84946911c9 100644 --- a/dumux/material/fluidstates/pressureoverlay.hh +++ b/dumux/material/fluidstates/pressureoverlay.hh @@ -40,7 +40,7 @@ public: * so it initially behaves exactly like the underlying fluid * state. */ - PressureOverlayFluidState(const FluidState &fs) + explicit PressureOverlayFluidState(const FluidState &fs) : fs_(&fs) { for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) diff --git a/dumux/material/fluidstates/saturationoverlay.hh b/dumux/material/fluidstates/saturationoverlay.hh index 9553a769f3..d09fa7d48b 100644 --- a/dumux/material/fluidstates/saturationoverlay.hh +++ b/dumux/material/fluidstates/saturationoverlay.hh @@ -40,7 +40,7 @@ public: * so it initially behaves exactly like the underlying fluid * state. */ - SaturationOverlayFluidState(const FluidState &fs) + explicit SaturationOverlayFluidState(const FluidState &fs) : fs_(&fs) { for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) diff --git a/dumux/material/fluidstates/temperatureoverlay.hh b/dumux/material/fluidstates/temperatureoverlay.hh index 2bb789b649..64a78ea260 100644 --- a/dumux/material/fluidstates/temperatureoverlay.hh +++ b/dumux/material/fluidstates/temperatureoverlay.hh @@ -40,7 +40,7 @@ public: * so it initially behaves exactly like the underlying fluid * state. */ - TemperatureOverlayFluidState(const FluidState &fs) + explicit TemperatureOverlayFluidState(const FluidState &fs) : fs_(&fs) { temperature_ = fs.temperature(/*phaseIdx=*/0); diff --git a/test/material/fluidmatrixinteractions/porenetwork/test_throattransmissibility.cc b/test/material/fluidmatrixinteractions/porenetwork/test_throattransmissibility.cc index deb08cd2a6..112d12ea35 100644 --- a/test/material/fluidmatrixinteractions/porenetwork/test_throattransmissibility.cc +++ b/test/material/fluidmatrixinteractions/porenetwork/test_throattransmissibility.cc @@ -31,7 +31,7 @@ struct MockFVElementGeometry struct MockFluxVariablesCacheOneP { using Scalar = double; - MockFluxVariablesCacheOneP(const PoreNetwork::Throat::Shape shape) + explicit MockFluxVariablesCacheOneP(const PoreNetwork::Throat::Shape shape) : shape_(shape) {} -- GitLab