I am using some Qt code that adds a VERIFY macro that looks something like this:
{ \
bool ok = cond; \
Q_ASSERT(ok); \
}
Then the code can use it, at the same time being sure that the condition is really evaluated, for example:
Q_ASSERT(callSomeFunction()); // callSomeFunction not evaluated in release builds!
VERIFY(callSomeFunction()); // callSomeFunction is always evaluated
Macro rejection, instead I would like to turn this into an inline function:
inline VERIFY(bool condition)
{
Q_ASSERT(condition);
}
However, in releases I am worried that the compiler will optimize all calls to this function (since it Q_ASSERTwill actually do nothing.) I am worried about unnecessary or, probably, depending on the flags of optimization / compiler / etc.? I think I could change it to:
inline VERIFY(bool condition)
{
condition;
Q_ASSERT(condition);
}
But, again, the compiler may be smart enough to ignore the call.
Is this built-in alternative safe for both debugging and release?