ENH: reset tmp via assignment from literal nullptr (#1775)

- previously this was marked as '= delete' for consistency with
  assignment from an empty pointer being a runtime error.
  However, these can be considered semantically different and it makes
  sense to permit this as equivalent to reset(nullptr).

  This change does not break existing code since the operator was
  previously unavailable (deleted).

STYLE: refactor tmp operator=(T*)

- delegate to reset() after initial checks
This commit is contained in:
Mark Olesen
2020-07-16 09:42:12 +02:00
parent 59bfbb9541
commit 35a0fd3e8e
4 changed files with 20 additions and 14 deletions

View File

@ -255,9 +255,8 @@ public:
// Fatal for a null pointer, or when the pointer is non-unique.
inline void operator=(T* p);
//- No assignment from literal nullptr.
// Consistent with run-time check for nullptr on assignment.
void operator=(std::nullptr_t) = delete;
//- Reset via assignment from literal nullptr
inline void operator=(std::nullptr_t) noexcept;
};

View File

@ -464,8 +464,6 @@ inline void Foam::tmp<T>::operator=(tmp<T>&& other) noexcept
template<class T>
inline void Foam::tmp<T>::operator=(T* p)
{
clear();
if (!p)
{
FatalErrorInFunction
@ -480,8 +478,14 @@ inline void Foam::tmp<T>::operator=(T* p)
<< abort(FatalError);
}
ptr_ = p;
type_ = PTR;
reset(p);
}
template<class T>
inline void Foam::tmp<T>::operator=(std::nullptr_t) noexcept
{
reset(nullptr);
}

View File

@ -234,9 +234,8 @@ public:
// Fatal for a null pointer
inline void operator=(T* p);
//- No assignment from literal nullptr.
// Consistent with run-time check for nullptr on assignment.
void operator=(std::nullptr_t) = delete;
//- Reset via assignment from literal nullptr
inline void operator=(std::nullptr_t) noexcept;
//- Conversion to tmp - releases pointer or copies reference
inline operator tmp<T>();

View File

@ -414,8 +414,6 @@ inline void Foam::tmpNrc<T>::operator=(tmpNrc<T>&& other) noexcept
template<class T>
inline void Foam::tmpNrc<T>::operator=(T* p)
{
clear();
if (!p)
{
FatalErrorInFunction
@ -423,8 +421,14 @@ inline void Foam::tmpNrc<T>::operator=(T* p)
<< abort(FatalError);
}
ptr_ = p;
type_ = PTR;
reset(p);
}
template<class T>
inline void Foam::tmpNrc<T>::operator=(std::nullptr_t) noexcept
{
reset(nullptr);
}