[cfe-dev] CLang 2.1 doesn't catch assert within if

Don Quixote de la Mancha quixote at dulcineatech.com
Fri Oct 7 23:21:16 PDT 2011


On Fri, Oct 7, 2011 at 10:37 PM, David Blaikie <dblaikie at gmail.com> wrote:
> Side note:  if you put a semicolon at the end of your assert, you should
> also be fine even in the case of empty assert definitions:
> if (x)
>   assert(y);
> z();
>
> would become:
>
> if (x)
>   ;
> z();

Yes, you are completely correct.  I ALWAYS put semicolons after
asserts, to make them look like any other function call.

But I am COMPLETELY CERTAIN that putting an assert() inside of an if
statement without also placing it in a Basic Block totally broke my
VC++ code.  The program I was integrating my library with was a
financial package that produced graphs.  If I graphed the output from
both my library and the client's old library, with my assert inside
the if, those two graphs subtly diverged.  When I fixed my code to use
a Basic Block instead, the two graphs coincided perfectly.

I still have the Visual Studio 7.0 installer.  I'm not sure but I
think 7.1 is an update one can download from Microsoft's site.  I
could install them both then just have a look at <assert.h> to see how
it is defined.

Even if all modern compilers do the right thing, I assert (!) it would
still be useful to write the analysis, as it would catch portability
problems.  There are lots of coders who still use broken old
compilers.  I still hear about people using Visual Studio 6!

Ever Faithful,

Don Quixote
-- 
Don Quixote de la Mancha
Dulcinea Technologies Corporation
Software of Elegance and Beauty
http://www.dulcineatech.com
quixote at dulcineatech.com




More information about the cfe-dev mailing list