[static_assert] Regression with gcc 3.4.2?

#include <boost/static_assert.hpp> template <typename T> struct foo { void bar(void) { BOOST_STATIC_ASSERT(false); } }; int main(void) { } --------------------------------------------------------------------- toot.cpp: In member function `void foo<T>::bar()': toot.cpp:8: error: invalid application of `sizeof' to incomplete type `boost::STATIC_ASSERTION_FAILURE< false>' --------------------------------------------------------------------- Is gcc wrong, or am I missing something really obvious? This used to work. And yes, I have the latest boost CVS snapshot. Dave

"David B. Held" <dheld@codelogicconsulting.com> wrote in message news:cihmvu$3ik$1@sea.gmane.org...
#include <boost/static_assert.hpp>
template <typename T> struct foo { void bar(void) { BOOST_STATIC_ASSERT(false); } };
int main(void) { }
Is gcc wrong, or am I missing something really obvious? This used to work. And yes, I have the latest boost CVS snapshot.
Apparently gcc is right. See http://lists.boost.org/MailArchives/boost/msg06980.php. The suggested workaround (maybe that's the wrong term, if it's not a bug) is: template<class T> struct always_false { enum { value = 0 }; }; template <typename T> struct foo { void bar(void) { BOOST_STATIC_ASSERT(always_false<T>::value); } }; Best Regards, Jonathan

Jonathan Turkanis wrote:
[...] Apparently gcc is right. See http://lists.boost.org/MailArchives/boost/msg06980.php.
The suggested workaround (maybe that's the wrong term, if it's not a bug) is:
template<class T> struct always_false { enum { value = 0 }; };
template <typename T> struct foo { void bar(void) { BOOST_STATIC_ASSERT(always_false<T>::value); } };
Ok, thanks. Should the always_false<> template get added somewhere permanent, or should we have a special case like BOOST_STATIC_ASSERT_FALSE? Dave

"David B. Held" <dheld@codelogicconsulting.com> wrote in message news:cii44q$ub5$1@sea.gmane.org...
Jonathan Turkanis wrote:
[...] Apparently gcc is right. See http://lists.boost.org/MailArchives/boost/msg06980.php.
The suggested workaround (maybe that's the wrong term, if it's not a bug) is:
template<class T> struct always_false { enum { value = 0 }; };
template <typename T> struct foo { void bar(void) { BOOST_STATIC_ASSERT(always_false<T>::value); } };
Ok, thanks. Should the always_false<> template get added somewhere permanent, or should we have a special case like BOOST_STATIC_ASSERT_FALSE?
I think the latter. Something like: namespace boost { namespace detail { template<class Dummy> struct always_false { enum { value = 0 }; }; } } // namespace #define BOOST_STATIC_ASSERT_FALSE(x) \ BOOST_STATIC_ASSERT(::boost::detail::always_false< x >::value); Of course we could also use: #define BOOST_STATIC_ASSERT_FALSE(x) \ BOOST_STATIC_ASSERT((mpl::apply<mpl::always<mpl::false_>, x>::value)); but that seems like overkill. Jonathan

Jonathan Turkanis wrote:
[...] namespace boost { namespace detail { template<class Dummy> struct always_false { enum { value = 0 }; }; } } // namespace
#define BOOST_STATIC_ASSERT_FALSE(x) \ BOOST_STATIC_ASSERT(::boost::detail::always_false< x >::value);
Beautiful. So who volunteers to put it somewhere appropriate?
Of course we could also use:
#define BOOST_STATIC_ASSERT_FALSE(x) \ BOOST_STATIC_ASSERT((mpl::apply<mpl::always<mpl::false_>, x>::value));
but that seems like overkill.
Hahahaha! If we have to resort to apply<>, we've definitely gone too far. Of course, someone will come up with a use case where apply<> should be used, and then I'll have to eat my words. :( Dave
participants (2)
-
David B. Held
-
Jonathan Turkanis