Boost logo

Boost Users :

Subject: Re: [Boost-users] Metaprogramming Question
From: Kim Barrett (kab.conundrums_at_[hidden])
Date: 2012-02-10 15:21:25


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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net