<cassert> in the boost libraries
Hello, we use our own assertion handler and assert macro in our code, defined in a header which gets included at the end of our precompiled header file. Unfortunately, many boost libraries undermine this because they include the cassert header, which redefines the assert macro. Currently we work around this by putting some boost libraries in the precompiled header and including our own assert header again in each source file which includes boost headers, but this is a clumsy and error-prone solution. Boost already nominately provides a solution through BOOST_ENABLE_ASSERT_HANDLER, but it's just not used consequently throughout the libraries. Could the authors of the libraries (or the reviewers) please grep through the code and change the cassert (or assert.h) includes to boost/assert.hpp, and consequently, change assert(...) to BOOST_ASSERT(...)? I've found the inclusion particularly often in the serialization, graph, iostream and random libraries, but also in regex, signals, ptr_container and many other headers. Regards, Joerg Ruedenauer
Joerg Ruedenauer
Hello,
we use our own assertion handler and assert macro in our code, defined in a header which gets included at the end of our precompiled header file. Unfortunately, many boost libraries undermine this because they include the cassert header, which redefines the assert macro.
That's a clue that you shouldn't be #defining assert.
Currently we work around this by putting some boost libraries in the precompiled header and including our own assert header again in each source file which includes boost headers, but this is a clumsy and error-prone solution. Boost already nominately provides a solution through BOOST_ENABLE_ASSERT_HANDLER, but it's just not used consequently throughout the libraries.
Could the authors of the libraries (or the reviewers) please grep through the code and change the cassert (or assert.h) includes to boost/assert.hpp, and consequently, change assert(...) to BOOST_ASSERT(...)?
It's a very good idea, and I think we should do it. That said, unless you stop #defining names that appear in legitimate standard library headers, you're bound to continue to have this problem, or others like it. -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams
Joerg Ruedenauer
writes: Hello,
we use our own assertion handler and assert macro in our code, defined in a header which gets included at the end of our precompiled header file. Unfortunately, many boost libraries undermine this because they include the cassert header, which redefines the assert macro.
That's a clue that you shouldn't be #defining assert.
Currently we work around this by putting some boost libraries in the precompiled header and including our own assert header again in each source file which includes boost headers, but this is a clumsy and error-prone solution. Boost already nominately provides a solution through BOOST_ENABLE_ASSERT_HANDLER, but it's just not used consequently throughout the libraries.
Could the authors of the libraries (or the reviewers) please grep through the code and change the cassert (or assert.h) includes to boost/assert.hpp, and consequently, change assert(...) to BOOST_ASSERT(...)?
It's a very good idea, and I think we should do it.
Although I guess we have to be pretty careful, since things like polymorphic_downcast are documented as using the standard assert macro. Technically speaking, it's a breaking change. -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
Could the authors of the libraries (or the reviewers) please grep through the code and change the cassert (or assert.h) includes to boost/assert.hpp, and consequently, change assert(...) to BOOST_ASSERT(...)?
It's a very good idea, and I think we should do it.
Although I guess we have to be pretty careful, since things like polymorphic_downcast are documented as using the standard assert macro. Technically speaking, it's a breaking change.
BOOST_ASSERT defaults to assert, though. So it might be acceptable, even though BOOST_ASSERT wasn't meant to be used in interfaces.
"Peter Dimov"
David Abrahams wrote:
Could the authors of the libraries (or the reviewers) please grep through the code and change the cassert (or assert.h) includes to boost/assert.hpp, and consequently, change assert(...) to BOOST_ASSERT(...)?
It's a very good idea, and I think we should do it.
Although I guess we have to be pretty careful, since things like polymorphic_downcast are documented as using the standard assert macro. Technically speaking, it's a breaking change.
BOOST_ASSERT defaults to assert, though. So it might be acceptable, even though BOOST_ASSERT wasn't meant to be used in interfaces.
That's why I said "technically speaking." Actually it occurs to me that our testing shouldn't use BOOST_ASSERT at all, but instead the test library or boost/detail/lightweight_test.hpp, the latter probably being slightly closer to a drop-in replacement for cassert. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
David Abrahams
-
Joerg Ruedenauer
-
Peter Dimov