Nat Goodspeed wrote:
In general, I think the major issue with changing macro contents from a simple statement to a compound statement is that it can have peculiar effects on code surrounding macro invocations. For instance (contrived example):
if (! data.valid()) BOOST_ASSERT(false); else { // ...process 'data'... }
Yes, I see. The semicolon would be a second empty statement. It would cause a compiler error.
The classic workaround is to wrap the compound statement in a no-op 'do' statement:
#define MACRO(stuff) do /* intended macro contents */ while (0)
Of course. the do-loop expects a semicolon as part of the statement. I've made the change. It works fine.
If there are special constraints unique to BOOST_ASSERT, I don't know them.
I see two possible reasons not to use this construction. 1. The programmer may not always want to abort (or throw) at an assertion failure. That's why I propose to make this behavior optional. 2. It may somehow become unsafe in multi-threaded programs. But I don't think this is a big issue. I would like to hear from the developer on this. -- Michiel Helvensteijn