I've written a basic macro which asserts regardless of debug or not:
#define ASSERT_ALWAYS(cond) \
do \
{ \
if (!cond) \
{ \
std::abort(); \
} \
} while(0) \
The strange thing is it compiles if I use a variable:
const bool s = myObj.anEnum != AnEnum::C;
ASSERT_ALWAYS(s);
but without the variable this doesn't compile:
ASSERT_ALWAYS(myObj.anEnum != AnEnum::C);
I get this compiler error:
error: no match for ‘operator!’ (operand type is ‘AnEnum::C’)
no known conversion for argument 1 from ‘AnEnum::C’ to ‘bool’
AnEnum is declared like this:
enum class AnEnum : char {
A = '0',
B = '2',
C
};
I get similar compiler errors for other types I try to change, so is the problem with my macro?