How to test that some code doesn't compile in C++? [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Unit test compile-time error I'm wondering if its possible to write a kind of unit test which will verify that a given code doesn't compile. For example, I have a template class: #include <boost/static_assert.hpp> #include <boost/type_traits/is_base_of.hpp> struct bar_base {}; template <typename T> class foo { BOOST_STATIC_ASSERT(::boost::is_base_of<T, bar_base>::value); }; So, the test should succeed with: