From 59bfbb9541fa15a69d39bcefc7ce82fcf252bd61 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 16 Jul 2020 11:57:32 +0200
Subject: [PATCH] ENH: simpler, more consistent checks for tmp validity (#1775)

- Previously considered to be valid() if it was any reference
  (null or non-null) or a non-null pointer.

  This appears to be a holdover from old code (pre-2015) where
  reinterpret_cast<..>(0) was used instead of the NullObject.

  A reference via a null pointer isn't really possible anywhere. Even
  for things like labelList::null(), they now use the NullObject,
  which has a non-zero memory location.

- now simply check for a non-zero memory address. Regardless of
  pointer or referenced object.
---
 src/OpenFOAM/memory/tmp/tmp.H    | 12 ++++++------
 src/OpenFOAM/memory/tmp/tmpNrc.H | 12 ++++++------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H
index ebd8f676c95..6369b5aa2be 100644
--- a/src/OpenFOAM/memory/tmp/tmp.H
+++ b/src/OpenFOAM/memory/tmp/tmp.H
@@ -160,11 +160,11 @@ public:
 
     // Query
 
-        //- True if a null managed pointer
-        bool empty() const noexcept { return !ptr_ && type_ == PTR; }
+        //- True if a null pointer/reference
+        bool empty() const noexcept { return !ptr_; }
 
-        //- True for non-null managed pointer or an object reference
-        bool valid() const noexcept { return ptr_ || type_ == CREF; }
+        //- True for non-null pointer/reference
+        bool valid() const noexcept { return ptr_; }
 
         //- True if this is a managed pointer (not a reference)
         bool isTmp() const noexcept { return type_ == PTR; }
@@ -241,8 +241,8 @@ public:
         //  Fatal for a null managed pointer or if the object is const.
         inline T* operator->();
 
-        //- Non-null managed pointer or an object reference : valid()
-        explicit operator bool() const noexcept { return ptr_ ||type_ == CREF; }
+        //- Non-null pointer/reference : valid()
+        explicit operator bool() const noexcept { return ptr_; }
 
         //- Transfer ownership of the managed pointer.
         //  Fatal for a null managed pointer or if the object is const.
diff --git a/src/OpenFOAM/memory/tmp/tmpNrc.H b/src/OpenFOAM/memory/tmp/tmpNrc.H
index 037b2ab97df..5dc589e156d 100644
--- a/src/OpenFOAM/memory/tmp/tmpNrc.H
+++ b/src/OpenFOAM/memory/tmp/tmpNrc.H
@@ -139,11 +139,11 @@ public:
 
     // Query
 
-        //- True if a null managed pointer
-        bool empty() const noexcept { return !ptr_ && type_ == PTR; }
+        //- True if a null pointer/reference
+        bool empty() const noexcept { return !ptr_; }
 
-        //- True for non-null managed pointer or an object reference
-        bool valid() const noexcept { return ptr_ || type_ == CREF; }
+        //- True for non-null pointer/reference
+        bool valid() const noexcept { return ptr_; }
 
         //- True if this is a managed pointer (not a reference)
         bool isTmp() const noexcept { return type_ == PTR; }
@@ -220,8 +220,8 @@ public:
         //  Fatal for a null managed pointer or if the object is const.
         inline T* operator->();
 
-        //- Non-null managed pointer or an object reference : valid()
-        explicit operator bool() const noexcept { return ptr_ ||type_ == CREF; }
+        //- Non-null pointer/reference : valid()
+        explicit operator bool() const noexcept { return ptr_; }
 
         //- Transfer ownership of the managed pointer.
         //  Fatal for a null managed pointer or if the object is const.
-- 
GitLab