From 4d1708ab0811b5125b39babcefbfb96d0d364350 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 22 Apr 2022 11:15:14 +0800 Subject: [PATCH] Fix NullPtrInfo warnings on GCC 11, ryzom/ryzomcore#646 --- nel/include/nel/misc/debug.h | 7 +++++++ nel/include/nel/misc/smart_ptr_inline.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/nel/include/nel/misc/debug.h b/nel/include/nel/misc/debug.h index 9b6e483768..44036111cb 100644 --- a/nel/include/nel/misc/debug.h +++ b/nel/include/nel/misc/debug.h @@ -380,6 +380,13 @@ extern bool _assertex_stop_1(bool &ignoreNextTime); #define nlassume(exp) do { } while (0) #endif +#if defined(NL_COMP_GCC) && (GCC_VERSION >= 40500) +// This may evaluate the expression at runtime if it has side effects, so it is not a desirable nlassume implementation in release mode +#define nlassumeex(exp) do { if (!(exp)) __builtin_unreachable(); } while (0) +#else +#define nlassumeex(exp) nlassume(exp) +#endif + #ifdef NL_NO_DEBUG # define nlassert(exp) nlassume(exp) # define nlassertonce(exp) nlassume(exp) diff --git a/nel/include/nel/misc/smart_ptr_inline.h b/nel/include/nel/misc/smart_ptr_inline.h index 1e950d710d..35cc61aacc 100644 --- a/nel/include/nel/misc/smart_ptr_inline.h +++ b/nel/include/nel/misc/smart_ptr_inline.h @@ -130,6 +130,8 @@ SMART_INLINE void CRefPtr::unRef() const } else { + // Guarantueed by !pinfo->IsNullPtrInfo + nlassumeex(pinfo != &CRefCount::NullPtrInfo); // If the CRefPtr still point to a valid object. if(pinfo->Ptr) {