From effd69a005535ad05807a98fc837da900c3f648d Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Mon, 15 Nov 2021 19:34:01 +0100
Subject: [PATCH] ENH: add refPtr release() method

- releases ownership of the pointer. A no-op (and returns nullptr)
  for references.

  Naming consistent with unique_ptr and autoPtr.

DOC: adjust wording for memory-related classes

- add is_const() method for tmp, refPtr.

  Drop (ununsed and confusing looking) isTmp method from refPtr
  in favour of is_pointer() or movable() checks

ENH: noexcept for some pTraits methods, remove redundant 'inline'

- test for const first for tmp/refPtr (simpler logic)
---
 applications/test/sizeof/Test-sizeof.C       |  3 +
 src/OpenFOAM/db/regIOobject/regIOobjectI.H   |  8 +--
 src/OpenFOAM/memory/autoPtr/autoPtr.H        | 41 +++++++------
 src/OpenFOAM/memory/autoPtr/autoPtrI.H       |  8 ++-
 src/OpenFOAM/memory/refPtr/refPtr.H          | 55 ++++++++++--------
 src/OpenFOAM/memory/refPtr/refPtrI.H         | 50 +++++++++-------
 src/OpenFOAM/memory/tmp/tmp.H                | 46 ++++++++-------
 src/OpenFOAM/memory/tmp/tmpI.H               | 60 ++++++++------------
 src/OpenFOAM/primitives/Scalar/Scalar.C      |  6 +-
 src/OpenFOAM/primitives/Scalar/Scalar.H      | 10 ++--
 src/OpenFOAM/primitives/bools/bool/bool.C    | 10 +++-
 src/OpenFOAM/primitives/bools/bool/bool.H    |  8 +--
 src/OpenFOAM/primitives/chars/char/char.C    |  7 ++-
 src/OpenFOAM/primitives/ints/int16/int16.H   |  2 +-
 src/OpenFOAM/primitives/ints/int32/int32.C   |  9 ++-
 src/OpenFOAM/primitives/ints/int32/int32.H   | 10 ++--
 src/OpenFOAM/primitives/ints/int64/int64.C   | 10 +++-
 src/OpenFOAM/primitives/ints/int64/int64.H   | 10 ++--
 src/OpenFOAM/primitives/ints/uint16/uint16.H |  2 +-
 src/OpenFOAM/primitives/ints/uint32/uint32.C | 10 +++-
 src/OpenFOAM/primitives/ints/uint32/uint32.H | 10 ++--
 src/OpenFOAM/primitives/ints/uint64/uint64.C |  9 ++-
 src/OpenFOAM/primitives/ints/uint64/uint64.H | 10 ++--
 src/OpenFOAM/primitives/ints/uint8/uint8.C   |  9 ++-
 src/OpenFOAM/primitives/ints/uint8/uint8.H   |  6 +-
 src/OpenFOAM/primitives/pTraits/pTraits.H    | 18 +++---
 src/OpenFOAM/primitives/strings/word/word.H  |  4 +-
 27 files changed, 238 insertions(+), 193 deletions(-)

diff --git a/applications/test/sizeof/Test-sizeof.C b/applications/test/sizeof/Test-sizeof.C
index 5232f06b5c8..dfebf13b59f 100644
--- a/applications/test/sizeof/Test-sizeof.C
+++ b/applications/test/sizeof/Test-sizeof.C
@@ -39,6 +39,7 @@ Description
 #include "argList.H"
 #include "Time.H"
 #include "IOobject.H"
+#include "scalarField.H"
 
 namespace Foam
 {
@@ -139,6 +140,8 @@ int main(int argc, char *argv[])
     cout<<"PstreamBuffers:" << sizeof(Foam::PstreamBuffers) << nl;
     cout<<"Time:" << sizeof(Foam::Time) << nl;
 
+    cout<<"tmp<>:" << sizeof(tmp<scalarField>) << nl;
+
     Info << "---\nEnd\n" << endl;
 
     return 0;
diff --git a/src/OpenFOAM/db/regIOobject/regIOobjectI.H b/src/OpenFOAM/db/regIOobject/regIOobjectI.H
index aa490b75ce6..144799397e9 100644
--- a/src/OpenFOAM/db/regIOobject/regIOobjectI.H
+++ b/src/OpenFOAM/db/regIOobject/regIOobjectI.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2015 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -98,12 +98,12 @@ inline Type& Foam::regIOobject::store(refPtr<Type>& ptr)
     if (ptr.is_pointer())
     {
         // Acquire ownership, pass management to objectRegistry
-        p = ptr.ptr();
+        p = ptr.release();
 
         store(p);
 
         // Change parameter to access the stored reference
-        ptr.cref(*p);
+        ptr.cref(p);
     }
     else
     {
@@ -144,7 +144,7 @@ inline Type& Foam::regIOobject::store(tmp<Type>& ptr)
         store(p);
 
         // Change parameter to access the stored reference
-        ptr.cref(*p);
+        ptr.cref(p);
     }
     else
     {
diff --git a/src/OpenFOAM/memory/autoPtr/autoPtr.H b/src/OpenFOAM/memory/autoPtr/autoPtr.H
index 4804275bb86..af002bc84ad 100644
--- a/src/OpenFOAM/memory/autoPtr/autoPtr.H
+++ b/src/OpenFOAM/memory/autoPtr/autoPtr.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -65,7 +65,7 @@ namespace Foam
 template<class T>
 class autoPtr
 {
-    //- Pointer to managed object
+    //- The managed pointer
     T* ptr_;
 
 
@@ -103,10 +103,10 @@ public:
 
     // Constructors
 
-        //- Construct with no managed object.
+        //- Construct with no managed pointer.
         inline constexpr autoPtr() noexcept;
 
-        //- Construct with no managed object (literal nullptr).
+        //- Construct with no managed pointer (literal nullptr).
         inline constexpr autoPtr(std::nullptr_t) noexcept;
 
         //- Construct, taking ownership of the pointer.
@@ -134,7 +134,7 @@ public:
         #endif
 
 
-    //- Deletes the managed object if such is present
+    //- Deletes the managed pointer
     inline ~autoPtr() noexcept;
 
 
@@ -142,14 +142,8 @@ public:
 
     // Query
 
-        //- Deprecated(2020-07) True if the managed pointer is null
-        //
-        //  \deprecated(2020-07) - use bool operator
-        FOAM_DEPRECATED_FOR(2020-07, "bool operator")
-        bool empty() const noexcept { return !ptr_; }
-
         //- True if the managed pointer is non-null
-        bool valid() const noexcept { return ptr_; }
+        bool valid() const noexcept { return bool(ptr_); }
 
 
     // Access
@@ -170,7 +164,7 @@ public:
 
     // Edit
 
-        //- Return pointer to the managed object and release ownership.
+        //- Release ownership and return the pointer.
         inline T* release() noexcept;
 
         //- Same as \c release().
@@ -182,11 +176,11 @@ public:
         void clear() noexcept { reset(nullptr); }
 
         //- Delete managed object and set to new given pointer
-        inline void reset(T* p = nullptr) noexcept;
+        //  \remark Same as move assign, but better for code documentation
+        inline void reset(autoPtr<T>&& other) noexcept;
 
         //- Delete managed object and set to new given pointer
-        //  \remark Same as move assign, but better for code documentation
-        inline void reset(autoPtr<T>&& ap) noexcept;
+        inline void reset(T* p = nullptr) noexcept;
 
         //- Swaps the managed object with other autoPtr.
         inline void swap(autoPtr<T>& other) noexcept;
@@ -230,7 +224,7 @@ public:
 
     // Casting
 
-        //- True if the managed pointer is non-null
+        //- True if pointer/reference is non-null. Same as valid()
         explicit operator bool() const noexcept { return bool(ptr_); }
 
         //- Cast to pointer type
@@ -253,6 +247,9 @@ public:
 
     // Assignment
 
+        //- No copy assignment from plain pointer (uncontrolled access)
+        void operator=(T* p) = delete;
+
         //- Transfer object ownership from parameter
         inline void operator=(autoPtr<T>&& ap) noexcept;
 
@@ -270,6 +267,12 @@ public:
 
     // Housekeeping
 
+        //- Deprecated(2020-07) True if the managed pointer is null
+        //
+        //  \deprecated(2020-07) - use bool operator
+        FOAM_DEPRECATED_FOR(2020-07, "bool operator")
+        bool empty() const noexcept { return !ptr_; }
+
         //- Deprecated(2018-02) Identical to reset().
         //  \note Provided for backward compatibility - the older version
         //      enforced a run-time check (Fatal if pointer was already set)
@@ -279,10 +282,6 @@ public:
         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
-        //  \deprecated(2018-02) Convenient, but uncontrolled access
-        void operator=(T* p) = delete;
 };
 
 
diff --git a/src/OpenFOAM/memory/autoPtr/autoPtrI.H b/src/OpenFOAM/memory/autoPtr/autoPtrI.H
index a8bce75464f..12411277421 100644
--- a/src/OpenFOAM/memory/autoPtr/autoPtrI.H
+++ b/src/OpenFOAM/memory/autoPtr/autoPtrI.H
@@ -114,9 +114,13 @@ inline void Foam::autoPtr<T>::reset(T* p) noexcept
 
 
 template<class T>
-inline void Foam::autoPtr<T>::reset(autoPtr<T>&& ap) noexcept
+inline void Foam::autoPtr<T>::reset(autoPtr<T>&& other) noexcept
 {
-    reset(ap.release());
+    if (&other != this)
+    {
+        // Ignore self-assignment
+        reset(other.release());
+    }
 }
 
 
diff --git a/src/OpenFOAM/memory/refPtr/refPtr.H b/src/OpenFOAM/memory/refPtr/refPtr.H
index d7cf643fd86..b78b5b0d8da 100644
--- a/src/OpenFOAM/memory/refPtr/refPtr.H
+++ b/src/OpenFOAM/memory/refPtr/refPtr.H
@@ -59,12 +59,12 @@ class refPtr
 {
     // Private Data
 
-        //- Object types
+        //- The stored reference type
         enum refType
         {
-            PTR,    //!< Managing a pointer (not ref-counted)
-            CREF,   //!< Using (const) reference to an object
-            REF     //!< Using (non-const) reference to an object
+            PTR,        //!< A managed pointer (not ref-counted)
+            CREF,       //!< A const reference to an object
+            REF         //!< A non-const reference to an object
         };
 
         //- The managed pointer or address of the object (reference)
@@ -111,10 +111,10 @@ public:
 
     // Constructors
 
-        //- Default construct, no managed pointer.
+        //- Construct with no managed pointer.
         inline constexpr refPtr() noexcept;
 
-        //- Construct with no managed pointer.
+        //- Construct with no managed pointer (literal nullptr).
         inline constexpr refPtr(std::nullptr_t) noexcept;
 
         //- Construct, taking ownership of the pointer.
@@ -151,21 +151,15 @@ public:
 
     // Query
 
-        //- Deprecated(2020-07) True if a null managed pointer
-        //
-        //  \deprecated(2020-07) - use bool operator
-        FOAM_DEPRECATED_FOR(2020-07, "bool operator")
-        bool empty() const noexcept { return !ptr_; }
-
         //- True for non-null pointer/reference
-        bool valid() const noexcept { return ptr_; }
+        bool valid() const noexcept { return bool(ptr_); }
+
+        //- If the stored/referenced content is const
+        bool is_const() const noexcept { return type_ == CREF; }
 
         //- True if this is a managed pointer (not a reference)
         bool is_pointer() const noexcept { return type_ == PTR; }
 
-        //- Identical to is_pointer()
-        bool isTmp() const noexcept { return type_ == PTR; }
-
         //- True if this is a non-null managed pointer
         inline bool movable() const noexcept;
 
@@ -196,6 +190,10 @@ public:
 
     // Edit
 
+        //- Release ownership and return the pointer.
+        //- A no-op for reference objects (returns nullptr).
+        inline T* release() noexcept;
+
         //- Return managed pointer for reuse, or clone() the object reference.
         inline T* ptr() const;
 
@@ -203,7 +201,10 @@ public:
         //- delete object and set pointer to nullptr
         inline void clear() const noexcept;
 
-        //- Delete managed temporary object and set to new given pointer
+        //- Clear existing and transfer ownership.
+        inline void reset(refPtr<T>&& other) noexcept;
+
+        //- Delete managed pointer and set to new given pointer
         inline void reset(T* p = nullptr) noexcept;
 
         //- Clear existing and transfer ownership from autoPtr.
@@ -212,21 +213,18 @@ public:
         //- Clear existing and transfer ownership from unique_ptr
         void reset(std::unique_ptr<T>&& other) { reset(other.release()); }
 
-        //- Clear existing and transfer ownership.
-        inline void reset(refPtr<T>&& other) noexcept;
-
         //- Clear existing and set (const) reference
         inline void cref(const T& obj) noexcept;
 
         //- Clear existing and set (const) reference to pointer content.
-        //  A null pointer is permitted (treated as a managed pointer).
+        //  The pointer can be null, which is handled like a clear().
         inline void cref(const T* p) noexcept;
 
         //- Clear existing and set (non-const) reference
         inline void ref(T& obj) noexcept;
 
         //- Clear existing and set (non-const) reference to pointer content.
-        //  A null pointer is permitted (treated as a managed pointer).
+        //  The pointer can be null, which is handled like a clear().
         inline void ref(T* p) noexcept;
 
         //- Swaps the managed object with other.
@@ -257,8 +255,8 @@ public:
         //- Cast to underlying data type, using the cref() method.
         operator const T&() const { return cref(); }
 
-        //- Non-null pointer/reference : valid()
-        explicit operator bool() const noexcept { return ptr_; }
+        //- True if pointer/reference is non-null. Same as valid()
+        explicit operator bool() const noexcept { return bool(ptr_); }
 
         //- Transfer ownership of the managed pointer.
         //  Fatal for a null managed pointer or if the object is const.
@@ -276,6 +274,15 @@ public:
 
         //- Conversion to tmp, releases pointer or shallow-copies reference
         inline operator tmp<T>();
+
+
+    // Housekeeping
+
+        //- Deprecated(2020-07) True if a null managed pointer
+        //
+        //  \deprecated(2020-07) - use bool operator
+        FOAM_DEPRECATED_FOR(2020-07, "bool operator")
+        bool empty() const noexcept { return !ptr_; }
 };
 
 
diff --git a/src/OpenFOAM/memory/refPtr/refPtrI.H b/src/OpenFOAM/memory/refPtr/refPtrI.H
index 7736fa301f5..0664701b180 100644
--- a/src/OpenFOAM/memory/refPtr/refPtrI.H
+++ b/src/OpenFOAM/memory/refPtr/refPtrI.H
@@ -186,41 +186,35 @@ inline bool Foam::refPtr<T>::movable() const noexcept
 template<class T>
 inline const T& Foam::refPtr<T>::cref() const
 {
-    if (type_ == PTR)
+    if (type_ == PTR && !ptr_)
     {
-        if (!ptr_)
-        {
-            FatalErrorInFunction
-                << this->typeName() << " deallocated"
-                << abort(FatalError);
-        }
+        FatalErrorInFunction
+            << this->typeName() << " deallocated"
+            << abort(FatalError);
     }
 
-    return *ptr_; // const reference
+    return *ptr_;  // const reference
 }
 
 
 template<class T>
 inline T& Foam::refPtr<T>::ref() const
 {
-    if (type_ == PTR)
+    if (type_ == CREF)
     {
-        if (!ptr_)
-        {
-            FatalErrorInFunction
-                << this->typeName() << " deallocated"
-                << abort(FatalError);
-        }
+        FatalErrorInFunction
+            << "Attempted non-const reference to const object: "
+            << this->typeName()
+            << abort(FatalError);
     }
-    else if (type_ == CREF)
+    else if (type_ == PTR && !ptr_)
     {
         FatalErrorInFunction
-            << "Attempted non-const reference to const object from a "
-            << this->typeName()
+            << this->typeName() << " deallocated"
             << abort(FatalError);
     }
 
-    return *ptr_; // non-const reference
+    return *ptr_;  // non-const reference
 }
 
 
@@ -231,6 +225,20 @@ inline T& Foam::refPtr<T>::constCast() const
 }
 
 
+template<class T>
+inline T* Foam::refPtr<T>::release() noexcept
+{
+    if (type_ == PTR)
+    {
+        T* p = ptr_;
+        ptr_ = nullptr;
+        return p;
+    }
+
+    return nullptr;
+}
+
+
 template<class T>
 inline T* Foam::refPtr<T>::ptr() const
 {
@@ -363,7 +371,7 @@ inline T& Foam::refPtr<T>::operator*()
     if (type_ == CREF)
     {
         FatalErrorInFunction
-            << "Attempt to cast const object to non-const for a "
+            << "Attempt to cast const object to non-const: "
             << this->typeName()
             << abort(FatalError);
     }
@@ -398,7 +406,7 @@ inline T* Foam::refPtr<T>::operator->()
     if (type_ == CREF)
     {
         FatalErrorInFunction
-            << "Attempt to cast const object to non-const for a "
+            << "Attempt to cast const object to non-const: "
             << this->typeName()
             << abort(FatalError);
     }
diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H
index 7a4272f0ee9..ccd2efc6242 100644
--- a/src/OpenFOAM/memory/tmp/tmp.H
+++ b/src/OpenFOAM/memory/tmp/tmp.H
@@ -66,12 +66,12 @@ class tmp
 {
     // Private Data
 
-        //- Object types
+        //- The stored reference type
         enum refType
         {
-            PTR,    //!< Managing a pointer (ref-counted)
-            CREF,   //!< Using (const) reference to an object
-            REF     //!< Using (non-const) reference to an object
+            PTR,        //!< A managed pointer (ref-counted)
+            CREF,       //!< A const reference to an object
+            REF         //!< A non-const reference to an object
         };
 
         //- The managed pointer or address of the object (reference)
@@ -125,10 +125,10 @@ public:
 
     // Constructors
 
-        //- Default construct, no managed pointer.
+        //- Construct with no managed pointer.
         inline constexpr tmp() noexcept;
 
-        //- Construct with no managed pointer.
+        //- Construct with no managed pointer (literal nullptr).
         inline constexpr tmp(std::nullptr_t) noexcept;
 
         //- Construct, taking ownership of the pointer.
@@ -166,14 +166,11 @@ public:
 
     // Query
 
-        //- Deprecated(2020-07) True if a null managed pointer
-        //
-        //  \deprecated(2020-07) - use bool operator
-        FOAM_DEPRECATED_FOR(2020-07, "bool operator")
-        bool empty() const noexcept { return !ptr_; }
+        //- True if pointer/reference is non-null
+        bool valid() const noexcept { return bool(ptr_); }
 
-        //- True for non-null pointer/reference
-        bool valid() const noexcept { return ptr_; }
+        //- If the stored/referenced content is const
+        bool is_const() const noexcept { return type_ == CREF; }
 
         //- True if this is a managed pointer (not a reference)
         bool is_pointer() const noexcept { return type_ == PTR; }
@@ -218,24 +215,24 @@ public:
         //- delete object and set pointer to nullptr
         inline void clear() const noexcept;
 
-        //- Delete managed temporary object and set to new given pointer
-        inline void reset(T* p = nullptr) noexcept;
-
         //- Clear existing and transfer ownership.
         inline void reset(tmp<T>&& other) noexcept;
 
+        //- Delete managed temporary object and set to new given pointer
+        inline void reset(T* p = nullptr) noexcept;
+
         //- Clear existing and set (const) reference
         inline void cref(const T& obj) noexcept;
 
         //- Clear existing and set (const) reference to pointer content.
-        //  A null pointer is permitted (treated as a managed pointer).
+        //  The pointer can be null, which is handled like a clear().
         inline void cref(const T* p) noexcept;
 
         //- Clear existing and set to (non-const) reference
         inline void ref(T& obj) noexcept;
 
         //- Clear existing and set (non-const) reference to pointer content.
-        //  A null pointer is permitted (treated as a managed pointer).
+        //  The pointer can be null, which is handled like a clear().
         inline void ref(T* p) noexcept;
 
         //- Swaps the managed object with other.
@@ -258,8 +255,8 @@ public:
         //- Cast to underlying data type, using the cref() method.
         operator const T&() const { return cref(); }
 
-        //- Non-null pointer/reference : valid()
-        explicit operator bool() const noexcept { return ptr_; }
+        //- True if pointer/reference is non-null. Same as valid()
+        explicit operator bool() const noexcept { return bool(ptr_); }
 
         //- Transfer ownership of the managed pointer.
         //  Fatal for a null managed pointer or if the object is const.
@@ -274,6 +271,15 @@ public:
 
         //- Reset via assignment from literal nullptr
         inline void operator=(std::nullptr_t) noexcept;
+
+
+    // Housekeeping
+
+        //- Deprecated(2020-07) True if a null managed pointer
+        //
+        //  \deprecated(2020-07) - use bool operator
+        FOAM_DEPRECATED_FOR(2020-07, "bool operator")
+        bool empty() const noexcept { return !ptr_; }
 };
 
 
diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H
index 094eab36a7a..b58eb7df37e 100644
--- a/src/OpenFOAM/memory/tmp/tmpI.H
+++ b/src/OpenFOAM/memory/tmp/tmpI.H
@@ -210,41 +210,35 @@ inline bool Foam::tmp<T>::movable() const noexcept
 template<class T>
 inline const T& Foam::tmp<T>::cref() const
 {
-    if (type_ == PTR)
+    if (type_ == PTR && !ptr_)
     {
-        if (!ptr_)
-        {
-            FatalErrorInFunction
-                << this->typeName() << " deallocated"
-                << abort(FatalError);
-        }
+        FatalErrorInFunction
+            << this->typeName() << " deallocated"
+            << abort(FatalError);
     }
 
-    return *ptr_; // const reference
+    return *ptr_;  // const reference
 }
 
 
 template<class T>
 inline T& Foam::tmp<T>::ref() const
 {
-    if (type_ == PTR)
+    if (type_ == CREF)
     {
-        if (!ptr_)
-        {
-            FatalErrorInFunction
-                << this->typeName() << " deallocated"
-                << abort(FatalError);
-        }
+        FatalErrorInFunction
+            << "Attempted non-const reference to const object: "
+            << this->typeName()
+            << abort(FatalError);
     }
-    else if (type_ == CREF)
+    else if (type_ == PTR && !ptr_)
     {
         FatalErrorInFunction
-            << "Attempted non-const reference to const object from a "
-            << this->typeName()
+            << this->typeName() << " deallocated"
             << abort(FatalError);
     }
 
-    return *ptr_; // non-const reference
+    return *ptr_;  // non-const reference
 }
 
 
@@ -387,14 +381,11 @@ inline void Foam::tmp<T>::swap(tmp<T>& other) noexcept
 template<class T>
 inline const T* Foam::tmp<T>::operator->() const
 {
-    if (type_ == PTR)
+    if (type_ == PTR && !ptr_)
     {
-        if (!ptr_)
-        {
-            FatalErrorInFunction
-                << this->typeName() << " deallocated"
-                << abort(FatalError);
-        }
+        FatalErrorInFunction
+            << this->typeName() << " deallocated"
+            << abort(FatalError);
     }
 
     return ptr_;
@@ -404,20 +395,17 @@ inline const T* Foam::tmp<T>::operator->() const
 template<class T>
 inline T* Foam::tmp<T>::operator->()
 {
-    if (type_ == PTR)
+    if (type_ == CREF)
     {
-        if (!ptr_)
-        {
-            FatalErrorInFunction
-                << this->typeName() << " deallocated"
-                << abort(FatalError);
-        }
+        FatalErrorInFunction
+            << "Attempt to cast const object to non-const: "
+            << this->typeName()
+            << abort(FatalError);
     }
-    else if (type_ == CREF)
+    else if (type_ == PTR && !ptr_)
     {
         FatalErrorInFunction
-            << "Attempt to cast const object to non-const for a "
-            << this->typeName()
+            << this->typeName() << " deallocated"
             << abort(FatalError);
     }
 
diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.C b/src/OpenFOAM/primitives/Scalar/Scalar.C
index cc096ebeb44..d6ec9d98595 100644
--- a/src/OpenFOAM/primitives/Scalar/Scalar.C
+++ b/src/OpenFOAM/primitives/Scalar/Scalar.C
@@ -31,7 +31,7 @@ License
 namespace Foam
 {
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const pTraits<Scalar>::typeName = "scalar";
 const char* const pTraits<Scalar>::componentNames[] = { "" };
@@ -45,7 +45,9 @@ const Scalar pTraits<Scalar>::rootMax = ScalarROOTVGREAT;
 const Scalar pTraits<Scalar>::vsmall = ScalarVSMALL;
 
 
-pTraits<Scalar>::pTraits(const Scalar& val)
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+pTraits<Scalar>::pTraits(const Scalar& val) noexcept
 :
     p_(val)
 {}
diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.H b/src/OpenFOAM/primitives/Scalar/Scalar.H
index bdb895628bd..e526027b365 100644
--- a/src/OpenFOAM/primitives/Scalar/Scalar.H
+++ b/src/OpenFOAM/primitives/Scalar/Scalar.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2016-2019 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -110,7 +110,7 @@ public:
     // Constructors
 
         //- Copy construct from primitive
-        explicit pTraits(const Scalar& val);
+        explicit pTraits(const Scalar& val) noexcept;
 
         //- Read construct from Istream
         explicit pTraits(Istream& is);
@@ -119,13 +119,13 @@ public:
     // Member Functions
 
         //- Access to the value
-        operator Scalar() const
+        operator Scalar() const noexcept
         {
             return p_;
         }
 
         //- Access to the value
-        operator Scalar&()
+        operator Scalar&() noexcept
         {
             return p_;
         }
@@ -143,7 +143,7 @@ word name(const Scalar val);
 template<>
 struct nameOp<Scalar>
 {
-    inline word operator()(const Scalar val) const
+    word operator()(const Scalar val) const
     {
         return Foam::name(val);
     }
diff --git a/src/OpenFOAM/primitives/bools/bool/bool.C b/src/OpenFOAM/primitives/bools/bool/bool.C
index 63da1e6a4f9..826f4c81566 100644
--- a/src/OpenFOAM/primitives/bools/bool/bool.C
+++ b/src/OpenFOAM/primitives/bools/bool/bool.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -31,7 +31,7 @@ License
 #include "error.H"
 #include "IOstreams.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::pTraits<bool>::typeName = "bool";
 const char* const Foam::pTraits<bool>::componentNames[] = { "" };
@@ -40,7 +40,9 @@ const bool Foam::pTraits<bool>::zero = false;
 const bool Foam::pTraits<bool>::one = true;
 
 
-Foam::pTraits<bool>::pTraits(const bool& p)
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::pTraits<bool>::pTraits(const bool& p) noexcept
 :
     p_(p)
 {}
@@ -52,6 +54,8 @@ Foam::pTraits<bool>::pTraits(Istream& is)
 }
 
 
+// * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
+
 Foam::Istream& Foam::operator>>(Istream& is, bool& b)
 {
     b = static_cast<bool>(Switch(is));
diff --git a/src/OpenFOAM/primitives/bools/bool/bool.H b/src/OpenFOAM/primitives/bools/bool/bool.H
index 8fc49b7cb6b..cbd4adc00da 100644
--- a/src/OpenFOAM/primitives/bools/bool/bool.H
+++ b/src/OpenFOAM/primitives/bools/bool/bool.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2020 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -109,7 +109,7 @@ public:
     // Constructors
 
         //- Copy construct from primitive
-        explicit pTraits(const bool& p);
+        explicit pTraits(const bool& p) noexcept;
 
         //- Read construct from Istream
         explicit pTraits(Istream& is);
@@ -118,13 +118,13 @@ public:
     // Member Functions
 
         //- Access to the value
-        operator bool() const
+        operator bool() const noexcept
         {
             return p_;
         }
 
         //- Access to the value
-        operator bool&()
+        operator bool&() noexcept
         {
             return p_;
         }
diff --git a/src/OpenFOAM/primitives/chars/char/char.C b/src/OpenFOAM/primitives/chars/char/char.C
index 6d5802816b6..de8e20e773f 100644
--- a/src/OpenFOAM/primitives/chars/char/char.C
+++ b/src/OpenFOAM/primitives/chars/char/char.C
@@ -29,10 +29,13 @@ License
 #include "char.H"
 #include "IOstreams.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::pTraits<char>::typeName = "char";
 
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
 Foam::pTraits<char>::pTraits(const char p) noexcept
 :
     p_(p)
@@ -45,6 +48,8 @@ Foam::pTraits<char>::pTraits(Istream& is)
 }
 
 
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
 char Foam::readChar(Istream& is)
 {
     char c;
diff --git a/src/OpenFOAM/primitives/ints/int16/int16.H b/src/OpenFOAM/primitives/ints/int16/int16.H
index 8ea19f1537e..a0f4341c5a7 100644
--- a/src/OpenFOAM/primitives/ints/int16/int16.H
+++ b/src/OpenFOAM/primitives/ints/int16/int16.H
@@ -61,7 +61,7 @@ inline word name(const int16_t val)
 template<>
 struct nameOp<int16_t>
 {
-    inline word operator()(const int16_t val) const
+    word operator()(const int16_t val) const
     {
         return word(std::to_string(int(val)), false); // Needs no stripping
     }
diff --git a/src/OpenFOAM/primitives/ints/int32/int32.C b/src/OpenFOAM/primitives/ints/int32/int32.C
index 2b10a9596d3..1453a8dd2e5 100644
--- a/src/OpenFOAM/primitives/ints/int32/int32.C
+++ b/src/OpenFOAM/primitives/ints/int32/int32.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2017-2018 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -28,7 +28,7 @@ License
 
 #include "int32.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::pTraits<int32_t>::componentNames[] = { "" };
 
@@ -39,7 +39,10 @@ const int32_t Foam::pTraits<int32_t>::max = INT32_MAX;
 const int32_t Foam::pTraits<int32_t>::rootMin = pTraits<int32_t>::min;
 const int32_t Foam::pTraits<int32_t>::rootMax = pTraits<int32_t>::max;
 
-Foam::pTraits<int32_t>::pTraits(const int32_t& val)
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::pTraits<int32_t>::pTraits(const int32_t& val) noexcept
 :
     p_(val)
 {}
diff --git a/src/OpenFOAM/primitives/ints/int32/int32.H b/src/OpenFOAM/primitives/ints/int32/int32.H
index 2cf170baf62..6b1e8f9a2ac 100644
--- a/src/OpenFOAM/primitives/ints/int32/int32.H
+++ b/src/OpenFOAM/primitives/ints/int32/int32.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -69,7 +69,7 @@ inline word name(const int32_t val)
 template<>
 struct nameOp<int32_t>
 {
-    inline word operator()(const int32_t val) const
+    word operator()(const int32_t val) const
     {
         return word(std::to_string(val), false); // Needs no stripping
     }
@@ -175,7 +175,7 @@ public:
     // Constructors
 
         //- Copy construct from primitive
-        explicit pTraits(const int32_t& val);
+        explicit pTraits(const int32_t& val) noexcept;
 
         //- Read construct from Istream
         explicit pTraits(Istream& is);
@@ -184,13 +184,13 @@ public:
     // Member Functions
 
         //- Access to the value
-        operator int32_t() const
+        operator int32_t() const noexcept
         {
             return p_;
         }
 
         //- Access to the value
-        operator int32_t&()
+        operator int32_t&() noexcept
         {
             return p_;
         }
diff --git a/src/OpenFOAM/primitives/ints/int64/int64.C b/src/OpenFOAM/primitives/ints/int64/int64.C
index c9b70990265..d305760d038 100644
--- a/src/OpenFOAM/primitives/ints/int64/int64.C
+++ b/src/OpenFOAM/primitives/ints/int64/int64.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2017-2018 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -28,7 +28,7 @@ License
 
 #include "int64.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::pTraits<int64_t>::componentNames[] = { "" };
 
@@ -39,11 +39,15 @@ const int64_t Foam::pTraits<int64_t>::max = INT64_MAX;
 const int64_t Foam::pTraits<int64_t>::rootMin = pTraits<int64_t>::min;
 const int64_t Foam::pTraits<int64_t>::rootMax = pTraits<int64_t>::max;
 
-Foam::pTraits<int64_t>::pTraits(const int64_t& val)
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::pTraits<int64_t>::pTraits(const int64_t& val) noexcept
 :
     p_(val)
 {}
 
+
 Foam::pTraits<int64_t>::pTraits(Istream& is)
 {
     is >> p_;
diff --git a/src/OpenFOAM/primitives/ints/int64/int64.H b/src/OpenFOAM/primitives/ints/int64/int64.H
index 0f9faf2757b..3d1fdc7c9b3 100644
--- a/src/OpenFOAM/primitives/ints/int64/int64.H
+++ b/src/OpenFOAM/primitives/ints/int64/int64.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -69,7 +69,7 @@ inline word name(const int64_t val)
 template<>
 struct nameOp<int64_t>
 {
-    inline word operator()(const int64_t val) const
+    word operator()(const int64_t val) const
     {
         return word(std::to_string(val), false); // Needs no stripping
     }
@@ -174,7 +174,7 @@ public:
     // Constructors
 
         //- Copy construct from primitive
-        explicit pTraits(const int64_t& val);
+        explicit pTraits(const int64_t& val) noexcept;
 
         //- Read construct from Istream
         explicit pTraits(Istream& is);
@@ -183,13 +183,13 @@ public:
     // Member Functions
 
         //- Access to the value
-        operator int64_t() const
+        operator int64_t() const noexcept
         {
             return p_;
         }
 
         //- Access to the value
-        operator int64_t&()
+        operator int64_t&() noexcept
         {
             return p_;
         }
diff --git a/src/OpenFOAM/primitives/ints/uint16/uint16.H b/src/OpenFOAM/primitives/ints/uint16/uint16.H
index c61d37e8225..7245c2d40a0 100644
--- a/src/OpenFOAM/primitives/ints/uint16/uint16.H
+++ b/src/OpenFOAM/primitives/ints/uint16/uint16.H
@@ -62,7 +62,7 @@ inline word name(const uint16_t val)
 template<>
 struct nameOp<uint16_t>
 {
-    inline word operator()(const uint16_t val) const
+    word operator()(const uint16_t val) const
     {
         return word(std::to_string(int(val)), false); // Needs no stripping
     }
diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.C b/src/OpenFOAM/primitives/ints/uint32/uint32.C
index 340ab250eb8..b1a040069a0 100644
--- a/src/OpenFOAM/primitives/ints/uint32/uint32.C
+++ b/src/OpenFOAM/primitives/ints/uint32/uint32.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2017 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -28,7 +28,7 @@ License
 
 #include "uint32.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::pTraits<uint32_t>::componentNames[] = { "" };
 
@@ -39,11 +39,15 @@ const uint32_t Foam::pTraits<uint32_t>::max = UINT32_MAX;
 const uint32_t Foam::pTraits<uint32_t>::rootMin = 0;
 const uint32_t Foam::pTraits<uint32_t>::rootMax = pTraits<uint32_t>::max;
 
-Foam::pTraits<uint32_t>::pTraits(const uint32_t& val)
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::pTraits<uint32_t>::pTraits(const uint32_t& val) noexcept
 :
     p_(val)
 {}
 
+
 Foam::pTraits<uint32_t>::pTraits(Istream& is)
 {
     is >> p_;
diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.H b/src/OpenFOAM/primitives/ints/uint32/uint32.H
index 69e7cb70b9b..5a3f574508e 100644
--- a/src/OpenFOAM/primitives/ints/uint32/uint32.H
+++ b/src/OpenFOAM/primitives/ints/uint32/uint32.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -68,7 +68,7 @@ inline word name(const uint32_t val)
 template<>
 struct nameOp<uint32_t>
 {
-    inline word operator()(const uint32_t val) const
+    word operator()(const uint32_t val) const
     {
         return word(std::to_string(val), false); // Needs no stripping
     }
@@ -161,7 +161,7 @@ public:
     // Constructors
 
         //- Copy construct from primitive
-        explicit pTraits(const uint32_t& val);
+        explicit pTraits(const uint32_t& val) noexcept;
 
         //- Read construct from Istream
         explicit pTraits(Istream& is);
@@ -170,13 +170,13 @@ public:
     // Member Functions
 
         //- Access to the value
-        operator uint32_t() const
+        operator uint32_t() const noexcept
         {
             return p_;
         }
 
         //- Access to the value
-        operator uint32_t&()
+        operator uint32_t&() noexcept
         {
             return p_;
         }
diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.C b/src/OpenFOAM/primitives/ints/uint64/uint64.C
index 804b86ac698..ca4f207d5b9 100644
--- a/src/OpenFOAM/primitives/ints/uint64/uint64.C
+++ b/src/OpenFOAM/primitives/ints/uint64/uint64.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2017 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -28,7 +28,7 @@ License
 
 #include "uint64.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::pTraits<uint64_t>::componentNames[] = { "" };
 
@@ -39,7 +39,10 @@ const uint64_t Foam::pTraits<uint64_t>::max = UINT64_MAX;
 const uint64_t Foam::pTraits<uint64_t>::rootMin = 0;
 const uint64_t Foam::pTraits<uint64_t>::rootMax = pTraits<uint64_t>::max;
 
-Foam::pTraits<uint64_t>::pTraits(const uint64_t& val)
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::pTraits<uint64_t>::pTraits(const uint64_t& val) noexcept
 :
     p_(val)
 {}
diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.H b/src/OpenFOAM/primitives/ints/uint64/uint64.H
index cc7624f8053..49dcb96e4a5 100644
--- a/src/OpenFOAM/primitives/ints/uint64/uint64.H
+++ b/src/OpenFOAM/primitives/ints/uint64/uint64.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -69,7 +69,7 @@ inline word name(const uint64_t val)
 template<>
 struct nameOp<uint64_t>
 {
-    inline word operator()(const uint64_t val) const
+    word operator()(const uint64_t val) const
     {
         return word(std::to_string(val), false); // Needs no stripping
     }
@@ -170,7 +170,7 @@ public:
     // Constructors
 
         //- Copy construct from primitive
-        explicit pTraits(const uint64_t& val);
+        explicit pTraits(const uint64_t& val) noexcept;
 
         //- Read construct from Istream
         explicit pTraits(Istream& is);
@@ -179,13 +179,13 @@ public:
     // Member Functions
 
         //- Access to the value
-        operator uint64_t() const
+        operator uint64_t() const noexcept
         {
             return p_;
         }
 
         //- Access to the value
-        operator uint64_t&()
+        operator uint64_t&() noexcept
         {
             return p_;
         }
diff --git a/src/OpenFOAM/primitives/ints/uint8/uint8.C b/src/OpenFOAM/primitives/ints/uint8/uint8.C
index 0c9cdf74bd3..52b52ee90d7 100644
--- a/src/OpenFOAM/primitives/ints/uint8/uint8.C
+++ b/src/OpenFOAM/primitives/ints/uint8/uint8.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -27,7 +27,7 @@ License
 
 #include "uint8.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 const char* const Foam::pTraits<uint8_t>::typeName = "uint8";
 const char* const Foam::pTraits<uint8_t>::componentNames[] = { "" };
@@ -40,11 +40,14 @@ const uint8_t Foam::pTraits<uint8_t>::rootMin = 0;
 const uint8_t Foam::pTraits<uint8_t>::rootMax = UINT8_MAX;
 
 
-Foam::pTraits<uint8_t>::pTraits(const uint8_t& val)
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::pTraits<uint8_t>::pTraits(const uint8_t& val) noexcept
 :
     p_(val)
 {}
 
+
 Foam::pTraits<uint8_t>::pTraits(Istream& is)
 {
     is >> p_;
diff --git a/src/OpenFOAM/primitives/ints/uint8/uint8.H b/src/OpenFOAM/primitives/ints/uint8/uint8.H
index 85d412c21d3..a45642adbf3 100644
--- a/src/OpenFOAM/primitives/ints/uint8/uint8.H
+++ b/src/OpenFOAM/primitives/ints/uint8/uint8.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -68,7 +68,7 @@ inline word name(const uint8_t val)
 template<>
 struct nameOp<uint8_t>
 {
-    inline word operator()(const uint8_t val) const
+    word operator()(const uint8_t val) const
     {
         return word(std::to_string(int(val)), false); // Needs no stripping
     }
@@ -126,7 +126,7 @@ public:
     // Constructors
 
         //- Copy construct from primitive
-        explicit pTraits(const uint8_t& val);
+        explicit pTraits(const uint8_t& val) noexcept;
 
         //- Read construct from Istream
         explicit pTraits(Istream& is);
diff --git a/src/OpenFOAM/primitives/pTraits/pTraits.H b/src/OpenFOAM/primitives/pTraits/pTraits.H
index f748c1b2a75..98c3a8136a2 100644
--- a/src/OpenFOAM/primitives/pTraits/pTraits.H
+++ b/src/OpenFOAM/primitives/pTraits/pTraits.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -28,7 +28,7 @@ Class
     Foam::pTraits
 
 Description
-    Traits class for primitives.
+    A traits class, which is primarily used for primitives.
 
     All primitives need a specialised version of this class. The
     specialised version will normally also require a conversion
@@ -51,25 +51,27 @@ class Istream;
                            Class pTraits Declaration
 \*---------------------------------------------------------------------------*/
 
-template<class PrimitiveType>
+// The base implementation is a pass-through to the base class.
+// Accordingly it inherits all static methods (eg, typeName etc).
+template<class Base>
 class pTraits
 :
-    public PrimitiveType
+    public Base
 {
 public:
 
     // Constructors
 
-        //- Copy construct from primitive
-        explicit pTraits(const PrimitiveType& p)
+        //- Copy construct from base class
+        explicit pTraits(const Base& obj)
         :
-            PrimitiveType(p)
+            Base(obj)
         {}
 
         //- Construct from Istream
         explicit pTraits(Istream& is)
         :
-            PrimitiveType(is)
+            Base(is)
         {}
 };
 
diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H
index d05abd312f3..19d9c2a8742 100644
--- a/src/OpenFOAM/primitives/strings/word/word.H
+++ b/src/OpenFOAM/primitives/strings/word/word.H
@@ -231,7 +231,7 @@ word name(const void* ptr);
 template<class T>
 struct nameOp
 {
-    inline word operator()(const T& obj) const
+    word operator()(const T& obj) const
     {
         return obj.name();
     }
@@ -242,7 +242,7 @@ struct nameOp
 template<class T>
 struct typeOp
 {
-    inline word operator()(const T& obj) const
+    word operator()(const T& obj) const
     {
         return obj.type();
     }
-- 
GitLab