diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H index 9afb78bcf..72a49def8 100644 --- a/src/OpenFOAM/memory/tmp/tmp.H +++ b/src/OpenFOAM/memory/tmp/tmp.H @@ -70,6 +70,11 @@ class tmp mutable T* ptr_; + // Private member operators + + inline void operator++(); + + public: // Constructors diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index 819c47142..a0dfdc6d2 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -26,6 +26,23 @@ License #include "error.H" #include +// * * * * * * * * * * * * * Private Member Operators * * * * * * * * * * * // + +template +inline void Foam::tmp::operator++() +{ + ptr_->operator++(); + + if (ptr_->count() > 1) + { + FatalErrorInFunction + << "Attempt to create more than 2 tmp's referring to" + " the same object of type " << typeName() + << abort(FatalError); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -62,7 +79,7 @@ inline Foam::tmp::tmp(const tmp& t) { if (ptr_) { - ptr_->operator++(); + operator++(); } else { @@ -90,7 +107,7 @@ inline Foam::tmp::tmp(const tmp& t, bool allowTransfer) } else { - ptr_->operator++(); + operator++(); } } else @@ -342,8 +359,7 @@ inline void Foam::tmp::operator=(const tmp& t) } ptr_ = t.ptr_; - - ptr_->operator++(); + t.ptr_ = 0; } else {