From 50b6af6d3dbb0a4ae070383902b058bf3ba7a7af Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 10 Dec 2016 18:55:31 +0100 Subject: [PATCH] Fixed: Strict aliasing warnings --HG-- branch : develop --- code/nel/include/nel/misc/resource_ptr.h | 2 +- .../include/nel/misc/resource_ptr_inline.h | 16 ++++++------- code/nel/include/nel/misc/smart_ptr.h | 16 +++++++------ code/nel/include/nel/misc/smart_ptr_inline.h | 24 +++++++++---------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/code/nel/include/nel/misc/resource_ptr.h b/code/nel/include/nel/misc/resource_ptr.h index 5773b7249..d11404f2c 100644 --- a/code/nel/include/nel/misc/resource_ptr.h +++ b/code/nel/include/nel/misc/resource_ptr.h @@ -108,7 +108,7 @@ template class CResourcePtr { private: - CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object. + CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object. TKey Key; // The key used to find the pointer mutable TPtr *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*() diff --git a/code/nel/include/nel/misc/resource_ptr_inline.h b/code/nel/include/nel/misc/resource_ptr_inline.h index b287e9b18..3a7087a3e 100644 --- a/code/nel/include/nel/misc/resource_ptr_inline.h +++ b/code/nel/include/nel/misc/resource_ptr_inline.h @@ -61,7 +61,7 @@ template SMART_INLINE void CReso if(pinfo->Ptr) { // Inform the Object that no more CResourcePtr points on it. - ((TPtr*)(pinfo->Ptr))->pinfo= static_cast(&CRefCount::NullPtrInfo); + ((TPtr*)(pinfo->Ptr))->pinfo = &CRefCount::NullPtrInfo; } // Then delete the pinfo. delete pinfo; @@ -74,7 +74,7 @@ template SMART_INLINE void CReso // Cons - dest. template inline CResourcePtr::CResourcePtr() { - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinf o= &CRefCount::NullPtrInfo; Ptr= NULL; REF_TRACE("Smart()"); @@ -95,7 +95,7 @@ template inline CResourcePtrRefCount++; } else - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; REF_TRACE("Smart(TPtr*)"); } @@ -117,7 +117,7 @@ template inline CResourcePtr(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; } @@ -142,7 +142,7 @@ template CResourcePtr(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; } @@ -179,7 +179,7 @@ template void CResourcePtr::k // First, release the refptr. unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; // Then delete the pointer. @@ -196,7 +196,7 @@ template inline CResourcePtrPtr; - if (pinfo != static_cast(&CRefCount::NullPtrInfo)) + if (pinfo != &CRefCount::NullPtrInfo) { // Does the pointer has been deleted ? if (Ptr == NULL) @@ -310,7 +310,7 @@ template void CStaticResourcePtr // First, release the refptr. unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; // Then delete the pointer. diff --git a/code/nel/include/nel/misc/smart_ptr.h b/code/nel/include/nel/misc/smart_ptr.h index 016097a3c..2273cebeb 100644 --- a/code/nel/include/nel/misc/smart_ptr.h +++ b/code/nel/include/nel/misc/smart_ptr.h @@ -43,7 +43,7 @@ public: /// Destructor which release pinfo if necessary. ~CRefCount(); /// Default constructor init crefs to 0. - CRefCount() { crefs = 0; pinfo=static_cast(&NullPtrInfo); } + CRefCount() { crefs = 0; pinfo = &NullPtrInfo; } /* The instance handle. Can't put those to private since must be used by CRefPtr (and friend doesn't work with template). @@ -56,6 +56,7 @@ public: sint RefCount; // RefCount of ptrinfo (!= instance) bool IsNullPtrInfo; // For dll problems, must use a flag to mark NullPtrInfo. }; + struct CPtrInfo : public CPtrInfoBase { CPtrInfo(CRefCount const* p) {Ptr=p; RefCount=0; IsNullPtrInfo=false;} @@ -75,13 +76,13 @@ public: // Can't put this to private since must be used by CSmartPtr (and friend doesn't work with template). // Provide incref()/decref() function doen't work since decref() can't do a delete this on a non virtual dtor. // So Ptr gestion can only be used via CSmartPtr. - mutable sint crefs; // The ref counter for SmartPtr use. - mutable CPtrInfo *pinfo; // The ref ptr for RefPtr use. + mutable sint crefs; // The ref counter for SmartPtr use. + mutable CPtrInfoBase *pinfo; // The ref ptr for RefPtr use. /// operator= must NOT copy crefs/pinfo!! CRefCount &operator=(const CRefCount &) {return *this;} /// copy cons must NOT copy crefs/pinfo!! - CRefCount(const CRefCount &) {crefs = 0; pinfo=static_cast(&NullPtrInfo);} + CRefCount(const CRefCount &) { crefs = 0; pinfo = &NullPtrInfo; } }; // To use CVirtualRefPtr (or if you just want to have a RefCount with virtual destructor), derive from this class. @@ -99,7 +100,7 @@ public: #define SMART_TRACE(_s) ((void)0) #define REF_TRACE(_s) ((void)0) //#define SMART_TRACE(_s) printf("%s: %d \n", _s, Ptr?Ptr->crefs:0) -//#define REF_TRACE(_s) printf("%s: %d \n", _s, pinfo!=&CRefCount::NullPtrInfo?pinfo->RefCount:0) +//#define REF_TRACE(_s) printf("%s: %d \n", _s, pinfo != &CRefCount::NullPtrInfo?pinfo->RefCount:0) /** @@ -294,7 +295,8 @@ template class CRefPtr { private: - CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object. + CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object. + mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*() void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted. @@ -380,7 +382,7 @@ template class CVirtualRefPtr { private: - CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object. + CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object. mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*() void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted. diff --git a/code/nel/include/nel/misc/smart_ptr_inline.h b/code/nel/include/nel/misc/smart_ptr_inline.h index f6665825a..1e950d710 100644 --- a/code/nel/include/nel/misc/smart_ptr_inline.h +++ b/code/nel/include/nel/misc/smart_ptr_inline.h @@ -134,7 +134,7 @@ SMART_INLINE void CRefPtr::unRef() const if(pinfo->Ptr) { // Inform the Object that no more CRefPtr points on it. - pinfo->Ptr->pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo->Ptr->pinfo = &CRefCount::NullPtrInfo; } // Then delete the pinfo. delete pinfo; @@ -148,7 +148,7 @@ SMART_INLINE void CRefPtr::unRef() const // Cons - dest. template inline CRefPtr::CRefPtr() { - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; REF_TRACE("Smart()"); @@ -170,7 +170,7 @@ template inline CRefPtr::CRefPtr(T *v) #endif } else - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; REF_TRACE("Smart(T*)"); } @@ -187,7 +187,7 @@ template inline CRefPtr::~CRefPtr(void) REF_TRACE("~Smart()"); unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; } @@ -216,7 +216,7 @@ template CRefPtr &CRefPtr::operator=(T *v) else { unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; } @@ -250,7 +250,7 @@ template void CRefPtr::kill() // First, release the refptr. unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; // Then delete the pointer. @@ -316,7 +316,7 @@ SMART_INLINE void CVirtualRefPtr::unRef() const if(pinfo->Ptr) { // Inform the Object that no more CVirtualRefPtr points on it. - pinfo->Ptr->pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo->Ptr->pinfo = &CRefCount::NullPtrInfo; } // Then delete the pinfo. delete pinfo; @@ -330,7 +330,7 @@ SMART_INLINE void CVirtualRefPtr::unRef() const // Cons - dest. template inline CVirtualRefPtr::CVirtualRefPtr() { - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; REF_TRACE("Smart()"); @@ -352,7 +352,7 @@ template inline CVirtualRefPtr::CVirtualRefPtr(T *v) #endif } else - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; REF_TRACE("Smart(T*)"); } @@ -370,7 +370,7 @@ template inline CVirtualRefPtr::~CVirtualRefPtr(void) REF_TRACE("~Smart()"); unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; } @@ -399,7 +399,7 @@ template CVirtualRefPtr &CVirtualRefPtr::operator=(T *v) else { unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; } @@ -435,7 +435,7 @@ template void CVirtualRefPtr::kill() // First, release the refptr. unRef(); - pinfo= static_cast(&CRefCount::NullPtrInfo); + pinfo = &CRefCount::NullPtrInfo; Ptr= NULL; // Then delete the pointer.