From 6e3bc1f7d077a8bc9a282df6fec15263d087fdcb Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 19 Nov 2020 12:40:47 +0100 Subject: [PATCH] STYLE: can add compile-time deprecated message for autoPtr::set() - deprecated Feb-2018, but not marked as such. The set() method originally enforce an additional run-time check (Fatal if pointer was already set), but this was rarely used. In fact, the set() method was invariably used in constructors where the pointer by definition was unset. Can now mark as deprecated to catch the last of these. We prefer reset() for similarity with std::unique_ptr Eg, FOAM_EXTRA_CXXFLAGS="-DFoam_autoPtr_deprecate_setMethod" wmake --- applications/test/autoPtr/Test-autoPtr.C | 7 +++++++ src/OpenFOAM/db/Time/Time.C | 13 ++++++++++-- .../lduMatrix/solvers/GAMG/GAMGSolver.C | 4 ++-- src/OpenFOAM/memory/autoPtr/autoPtr.H | 6 +++++- .../processorCyclicPolyPatch.C | 2 +- .../field/columnAverage/columnAverage.C | 6 +++--- .../field/surfaceDistance/surfaceDistance.C | 4 ++-- .../distributedTriSurfaceMesh.C | 8 +++---- .../PurePhaseModel/PurePhaseModel.C | 7 ++++--- .../phaseSystem/phaseSystemTemplates.C | 2 +- .../populationBalanceModel.C | 21 ++++++++++--------- .../twoPhaseSystem/twoPhaseSystem.C | 18 ++++++++-------- .../wideBandAbsorptionEmission.C | 2 +- 13 files changed, 61 insertions(+), 39 deletions(-) diff --git a/applications/test/autoPtr/Test-autoPtr.C b/applications/test/autoPtr/Test-autoPtr.C index ed621ea0f2..e084ffb7ee 100644 --- a/applications/test/autoPtr/Test-autoPtr.C +++ b/applications/test/autoPtr/Test-autoPtr.C @@ -25,6 +25,8 @@ License \*---------------------------------------------------------------------------*/ +// #define Foam_autoPtr_deprecate_setMethod + #include #include "autoPtr.H" #include "labelList.H" @@ -236,6 +238,11 @@ int main(int argc, char *argv[]) // Does compile (good!): ptr1 = nullptr; ptr1.reset(std::move(ptr2)); + + autoPtr ptr3; + + // set() method - deprecated warning? + ptr3.set(ptr1.release()); } diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index dbc1c8214c..3b05a0af1d 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -1087,7 +1087,16 @@ void Foam::Time::setDeltaT(const scalar deltaT, const bool adjust) Foam::TimeState Foam::Time::subCycle(const label nSubCycles) { - prevTimeState_.set(new TimeState(*this)); // Fatal if already set + #ifdef FULLDEBUG + if (prevTimeState_) + { + FatalErrorInFunction + << "previous time state already set" << nl + << exit(FatalError); + } + #endif + + prevTimeState_.reset(new TimeState(*this)); setTime(*this - deltaT(), (timeIndex() - 1)*nSubCycles); deltaT_ /= nSubCycles; @@ -1118,7 +1127,7 @@ void Foam::Time::endSubCycle() if (subCycling_) { TimeState::operator=(prevTimeState()); - prevTimeState_.clear(); + prevTimeState_.reset(nullptr); } subCycling_ = 0; diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C index d445e4d1f4..946ae1d49f 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolver.C @@ -288,7 +288,7 @@ Foam::GAMGSolver::GAMGSolver } else if (matrixLevels_[coarsestLevel].asymmetric()) { - coarsestSolverPtr_.set + coarsestSolverPtr_.reset ( new PBiCGStab ( @@ -303,7 +303,7 @@ Foam::GAMGSolver::GAMGSolver } else { - coarsestSolverPtr_.set + coarsestSolverPtr_.reset ( new PCG ( diff --git a/src/OpenFOAM/memory/autoPtr/autoPtr.H b/src/OpenFOAM/memory/autoPtr/autoPtr.H index 2ac54bdecd..4804275bb8 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtr.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtr.H @@ -49,6 +49,7 @@ SourceFiles // Transitional features/misfeatures #define Foam_autoPtr_copyConstruct #define Foam_autoPtr_castOperator +// #define Foam_autoPtr_deprecate_setMethod #include "stdFoam.H" @@ -163,7 +164,7 @@ public: //- Return reference to the managed object without nullptr checking. // When get() == nullptr, additional guards may be required to avoid - // inadvertent access to a nullptr. + // inadvertent access of a nullptr. T& ref() { return *ptr_; } @@ -274,6 +275,9 @@ public: // enforced a run-time check (Fatal if pointer was already set) // but this was rarely used. // \deprecated(2018-02) Identical to reset(). + #ifdef Foam_autoPtr_deprecate_setMethod + FOAM_DEPRECATED_FOR(2018-02, "reset() - same behaviour") + #endif void set(T* p) noexcept { reset(p); } //- Deprecated(2018-02) No copy assignment from plain pointer diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processorCyclic/processorCyclicPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processorCyclic/processorCyclicPolyPatch.C index 14e6ca4e48..939f26210a 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processorCyclic/processorCyclicPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processorCyclic/processorCyclicPolyPatch.C @@ -348,7 +348,7 @@ bool Foam::processorCyclicPolyPatch::order UIPstream fromNeighbour(neighbProcNo(), pBufs); fromNeighbour >> masterPts >> masterFaces; SubList fcs(masterFaces, masterFaces.size()); - masterPtr.set(new primitivePatch(fcs, masterPts)); + masterPtr.reset(new primitivePatch(fcs, masterPts)); } const cyclicPolyPatch& cycPatch = diff --git a/src/functionObjects/field/columnAverage/columnAverage.C b/src/functionObjects/field/columnAverage/columnAverage.C index 65623a8e73..0ef1f074c9 100644 --- a/src/functionObjects/field/columnAverage/columnAverage.C +++ b/src/functionObjects/field/columnAverage/columnAverage.C @@ -88,9 +88,9 @@ Foam::functionObjects::columnAverage::meshAddressing(const polyMesh& mesh) const mesh.points() ); - globalFaces_.set(new globalIndex(uip.size())); - globalEdges_.set(new globalIndex(uip.nEdges())); - globalPoints_.set(new globalIndex(uip.nPoints())); + globalFaces_.reset(new globalIndex(uip.size())); + globalEdges_.reset(new globalIndex(uip.nEdges())); + globalPoints_.reset(new globalIndex(uip.nPoints())); meshStructurePtr_.reset ( new meshStructure diff --git a/src/functionObjects/field/surfaceDistance/surfaceDistance.C b/src/functionObjects/field/surfaceDistance/surfaceDistance.C index 6f08a77b5e..81a96f5e62 100644 --- a/src/functionObjects/field/surfaceDistance/surfaceDistance.C +++ b/src/functionObjects/field/surfaceDistance/surfaceDistance.C @@ -85,8 +85,8 @@ bool Foam::functionObjects::surfaceDistance::read doCells_ = dict.getOrDefault("calculateCells", true); - geomPtr_.clear(); - geomPtr_.set + geomPtr_.reset(nullptr); + geomPtr_.reset ( new searchableSurfaces ( diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index 80aa0bce58..293b5058cf 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -3098,9 +3098,9 @@ void Foam::distributedTriSurfaceMesh::findNearest { sendMap[proci].transfer(dynSendMap[proci]); } - map1Ptr.set(new mapDistribute(std::move(sendMap))); + map1Ptr.reset(new mapDistribute(std::move(sendMap))); } - const mapDistribute& map1 = map1Ptr(); + const mapDistribute& map1 = *map1Ptr; if (debug) @@ -4116,9 +4116,9 @@ void Foam::distributedTriSurfaceMesh::getVolumeType } } - mapPtr.set(new mapDistribute(std::move(sendMap))); + mapPtr.reset(new mapDistribute(std::move(sendMap))); } - const mapDistribute& map = mapPtr(); + const mapDistribute& map = *mapPtr; // Get the points I need to test pointField localPoints(samples); diff --git a/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/PurePhaseModel/PurePhaseModel.C b/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/PurePhaseModel/PurePhaseModel.C index e06091e1f3..9415a138ea 100644 --- a/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/PurePhaseModel/PurePhaseModel.C +++ b/src/phaseSystemModels/multiphaseInter/phasesSystem/phaseModel/PurePhaseModel/PurePhaseModel.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,7 @@ License #include "PurePhaseModel.H" #include "phaseSystem.H" #include "basicThermo.H" + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -39,14 +40,14 @@ Foam::PurePhaseModel::PurePhaseModel : BasePhaseModel(fluid, phaseName) { - thermoPtr_.set + thermoPtr_.reset ( phaseThermo::New ( fluid.mesh(), phaseName, basicThermo::phasePropertyName(basicThermo::dictName, phaseName) - ).ptr() + ) ); } diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseSystem/phaseSystemTemplates.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseSystem/phaseSystemTemplates.C index c16b2dfec0..c507861860 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseSystem/phaseSystemTemplates.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseSystem/phaseSystemTemplates.C @@ -212,7 +212,7 @@ void Foam::phaseSystem::generatePairsAndSubModels << exit(FatalError); } - models[key][pair.index(phase)].set(tempModelIter().ptr()); + models[key][pair.index(phase)].reset(tempModelIter().ptr()); } } } diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/populationBalanceModel/populationBalanceModel/populationBalanceModel.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/populationBalanceModel/populationBalanceModel/populationBalanceModel.C index 8aef864303..c50ba7996a 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/populationBalanceModel/populationBalanceModel/populationBalanceModel.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/populationBalanceModel/populationBalanceModel/populationBalanceModel.C @@ -953,7 +953,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel if (coalescence_.size() != 0) { - coalescenceRate_.set + coalescenceRate_.reset ( new volScalarField ( @@ -971,7 +971,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel if (breakup_.size() != 0) { - breakupRate_.set + breakupRate_.reset ( new volScalarField ( @@ -989,7 +989,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel if (binaryBreakup_.size() != 0) { - binaryBreakupRate_.set + binaryBreakupRate_.reset ( new volScalarField ( @@ -1012,7 +1012,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel if (drift_.size() != 0) { - driftRate_.set + driftRate_.reset ( new volScalarField ( @@ -1027,7 +1027,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel ) ); - rx_.set + rx_.reset ( new volScalarField ( @@ -1042,7 +1042,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel ) ); - rdx_.set + rdx_.reset ( new volScalarField ( @@ -1060,7 +1060,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel if (nucleation_.size() != 0) { - nucleationRate_.set + nucleationRate_.reset ( new volScalarField ( @@ -1083,7 +1083,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel if (velocityGroups_.size() > 1) { - alphas_.set + alphas_.reset ( new volScalarField ( @@ -1100,7 +1100,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel ) ); - dsm_.set + dsm_.reset ( new volScalarField ( @@ -1117,7 +1117,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel ) ); - U_.set + U_.reset ( new volVectorField ( @@ -1141,6 +1141,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel Foam::diameterModels::populationBalanceModel::~populationBalanceModel() {} + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::autoPtr diff --git a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C index 7093ecd55c..f4198b56fd 100644 --- a/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C +++ b/src/phaseSystemModels/twoPhaseEuler/twoPhaseSystem/twoPhaseSystem/twoPhaseSystem.C @@ -136,7 +136,7 @@ Foam::twoPhaseSystem::twoPhaseSystem phasePair::scalarTable sigmaTable(lookup("sigma")); phasePair::dictTable aspectRatioTable(lookup("aspectRatio")); - pair_.set + pair_.reset ( new phasePair ( @@ -147,7 +147,7 @@ Foam::twoPhaseSystem::twoPhaseSystem ) ); - pair1In2_.set + pair1In2_.reset ( new orderedPhasePair ( @@ -159,7 +159,7 @@ Foam::twoPhaseSystem::twoPhaseSystem ) ); - pair2In1_.set + pair2In1_.reset ( new orderedPhasePair ( @@ -174,7 +174,7 @@ Foam::twoPhaseSystem::twoPhaseSystem // Models - drag_.set + drag_.reset ( new BlendedInterfacialModel ( @@ -191,7 +191,7 @@ Foam::twoPhaseSystem::twoPhaseSystem ) ); - virtualMass_.set + virtualMass_.reset ( new BlendedInterfacialModel ( @@ -207,7 +207,7 @@ Foam::twoPhaseSystem::twoPhaseSystem ) ); - heatTransfer_.set + heatTransfer_.reset ( new BlendedInterfacialModel ( @@ -223,7 +223,7 @@ Foam::twoPhaseSystem::twoPhaseSystem ) ); - lift_.set + lift_.reset ( new BlendedInterfacialModel ( @@ -239,7 +239,7 @@ Foam::twoPhaseSystem::twoPhaseSystem ) ); - wallLubrication_.set + wallLubrication_.reset ( new BlendedInterfacialModel ( @@ -255,7 +255,7 @@ Foam::twoPhaseSystem::twoPhaseSystem ) ); - turbulentDispersion_.set + turbulentDispersion_.reset ( new BlendedInterfacialModel ( diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C index 9444a1e9a1..cfbafa2fcd 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.C @@ -111,7 +111,7 @@ Foam::radiation::wideBandAbsorptionEmission::wideBandAbsorptionEmission && "none" != coeffsDict_.get("lookUpTableFileName") ) { - lookUpTablePtr_.set + lookUpTablePtr_.reset ( new interpolationLookUpTable (