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) {