On Feb 10, 2012, at 2:46 PM, Michael Schulze wrote:
That is not a bug of gcc. It is right if it states that the interpretation could be done in two way either the else belongs to the first if or to the second one. However, you can make yourself and the compiler happy. Try the following.
#define MY_FANCY_ASSERT(cond, str) \ do { if (cond) {} else format(str) % __FILE__ % __LINE__ } while(0)
With this you have encapsulated the if-else statement and the compiler has now no reasons to complain anymore.
I think you missed the point of all this. The macro is intended to be followed by user code to add stuff to the output, e.g. MY_FANCY_ASSERT(pred, str) % value1 % value2; The above suggestion prevents that. I'm quite familiar with that do/while(0); it's just not what's needed in this case. The potential gcc bugs I mentioned had nothing to do with the warning itself, but rather with my inability to use existing (in recent versions at least) mechanisms for locally disabling the warning. I think inserting appropriate _Pragma forms into the macro expansion should have worked but didn't.