[cfe-dev] CLang 2.1 doesn't catch assert within if
David Blaikie
dblaikie at gmail.com
Fri Oct 7 22:37:33 PDT 2011
On Fri, Oct 7, 2011 at 10:23 PM, Don Quixote de la Mancha <
quixote at dulcineatech.com> wrote:
> On Fri, Oct 7, 2011 at 10:16 PM, Charles Davis <cdavis at mymail.mines.edu>
> wrote:
> >
> > On Oct 7, 2011, at 11:02 PM, Don Quixote de la Mancha wrote:
> >>
> >> If NDEBUG is defined as for a release or profile build, you'll get the
> >> following in your preprocessed code, which will be very hard to debug:
> >>
> >> if ( condition )
> >> following_line();
> > No it won't. It will look like this:
> > if ( condition )
> > (void)0;
> >
> > following_line();
> >
> > That's because, when NDEBUG is defined, assert(3) is defined like so:
> >
> > #define assert(cond) (void)0
>
> You wrote that as "assert(3)" which suggests you are referring to a
> UNIX man page. When I got bit in the ass by putting assert() in a
> conditional, it was with Microsoft Visual C++ 7 or maybe 7.1.
>
I can't speak for old versions, but at least VS 2010 Express defines assert
in non-debug as:
#define assert(_Expression) ((void)0)
so it looks OK.
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();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111007/80bf6414/attachment.html>
More information about the cfe-dev
mailing list