Hi,
the (really useful!) boost test library provides the test tool macro
BOOST_CHECK_EQUAL() which checks two values for equality. I just learned
the hard way that the following does not do what one would expect.
char const *p = 0;
BOOST_CHECK_EQUAL(p, p);
On my system, this results in a test program crash. The reason is, for
this parameter type strcmp() is called which (of course) doesn't like
NULL pointers as it's arguments.
This isn't documented anywhere in the test library documentation
(neither the special treatment of char * nor the requirement that those
must not be NULL) and I think it needs to be fixed. There are several
possible ways.
1. Just document it. Not so good, IMHO.
2. Document the special case and add a check for NULL pointers before
calling strcmp().
3. Remove the special case alltogether. After all, I might want to check
that the pointers are equal and not the string they point to. This might
be the best solution, but breaks backward compatibility.
Markus
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
- Re: [boost] BOOST_CHECK_EQUAL() dangers Markus Schöpflin
- Re: [boost] BOOST_CHECK_EQUAL() dangers David Abrahams
- [boost] Re: BOOST_CHECK_EQUAL() dangers Gennadiy Rozental
- Re: [boost] Re: BOOST_CHECK_EQUAL() dangers David Abrahams
- [boost] Re: BOOST_CHECK_EQUAL() dangers Markus Schöpflin
- [boost] Re: BOOST_CHECK_EQUAL() dangers Gennadiy Rozental
- [boost] Re: BOOST_CHECK_EQUAL() dangers Markus Schöpflin
- [boost] Re: BOOST_CHECK_EQUAL() dangers Alisdair Meredith
- RE: [boost] BOOST_CHECK_EQUAL() dangers Chris Parsons