Dear All, I am encountering a problem with BOOST_STATIC_ASSERT, it is producing compile-time errors that are a little cryptic. When using BOOST_STATIC_ASSERT such as class rtm : public matrix<ElementType> { BOOST_STATIC_ASSERT(::boost::is_float<ElementType>::value || ejg::boost::is_complex<ElementType>::value); public: ... ... .. Instantiation of the rtm class with a non float or non complex type, such as: ejg::oned::rtm<char> M; causes the following compiler error. error: invalid application of sizeof to incomplete type boost::STATIC_ASSERTION_FAILURE<false> Boost 1.32.0 g++ 4.0.1 Obviously generating a compiler error is the correct behaviour, I want to make sure that only complex or float type objects are instantiated. The problem is that the compiler error is rather cryptic.
From the documentation of boost http://www.boost.org/doc/html/boost_staticassert.html, I should be seeing
Illegal use of STATIC_ASSERTION_FAILURE<false> Is there any way this can be improved by generating the error or is it too much of a compiler issue? -ed
error: invalid application of sizeof to incomplete type boost::STATIC_ASSERTION_FAILURE<false>
Boost 1.32.0 g++ 4.0.1
Obviously generating a compiler error is the correct behaviour, I want to make sure that only complex or float type objects are instantiated. The problem is that the compiler error is rather cryptic.
From the documentation of boost http://www.boost.org/doc/html/boost_staticassert.html, I should be seeing
Illegal use of STATIC_ASSERTION_FAILURE<false>
Is there any way this can be improved by generating the error or is it too much of a compiler issue?
Sigh... It's very compiler specific I'm afraid, we can STATIC_ASSERTION_FAILURE into the message but that's about it at present. John.
John Maddock wrote:
Is there any way this can be improved by generating the error or is it too much of a compiler issue?
Sigh... It's very compiler specific I'm afraid, we can STATIC_ASSERTION_FAILURE into the message but that's about it at present.
Rename it to "This_means_the_static_assertion_failed_Please_check_the_assertion"? Ben.
Edward Grace wrote:
error: invalid application of sizeof to incomplete type boost::STATIC_ASSERTION_FAILURE<false>
Boost 1.32.0 g++ 4.0.1
Obviously generating a compiler error is the correct behaviour, I want to make sure that only complex or float type objects are instantiated. The problem is that the compiler error is rather cryptic.
From the documentation of boost
http://www.boost.org/doc/html/boost_staticassert.html, I should be seeing
Illegal use of STATIC_ASSERTION_FAILURE<false>
Is there any way this can be improved by generating the error or is it too much of a compiler issue?
John Maddock wrote:
Sigh... It's very compiler specific I'm afraid, we can STATIC_ASSERTION_FAILURE into the message but that's about it at present.
Actually I've implemented an alternative STATIC_ASSERT macro that let's one add two identifiers to better describe the error. One would be a title and the other a more descriptive message. The original motivation for this was to diagnose a missing include file for Phoenix! One would get an error message containing missing_include::boost_spirit_phoenix_comma_hpp when trying to use the comma operator without the above include. The latest implementation is available here, http://svn.berlios.de/wsvn/breeze/trunk/breeze/static_assert.hpp?op=file (Sorry for the long url, tinyurl is not working properly, right now) It was tested with some versions of gcc (3.3/4 and 4) and Borland 5.5.1. I believe it used to work with MSVC 7.1 but I haven't tested lately. Regards, João Abecasis
João Abecasis
John Maddock wrote:
Sigh... It's very compiler specific I'm afraid, we can STATIC_ASSERTION_FAILURE into the message but that's about it at present.
Actually I've implemented an alternative STATIC_ASSERT macro that let's one add two identifiers to better describe the error. One would be a title and the other a more descriptive message.
The original motivation for this was to diagnose a missing include file for Phoenix! One would get an error message containing
missing_include::boost_spirit_phoenix_comma_hpp
when trying to use the comma operator without the above include.
Have you considered using the MPL static assertion macros? They usually generate much better error messages than those you get from BOOST_STATIC_ASSERT. -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
Have you considered using the MPL static assertion macros? They usually generate much better error messages than those you get from BOOST_STATIC_ASSERT.
For some definition of better, anyway ;-) Joel de Guzman encouraged me to develop my own static assert to its present shape. Here's what he had to say, http://tinyurl.com/dxuyz Regards, João
The latest implementation is available here,
http://svn.berlios.de/wsvn/breeze/trunk/breeze/static_assert.hpp?op=file (Sorry for the long url, tinyurl is not working properly, right now)
My brouser is mangling that, can you mail a copy privately to john@johnmaddock.co.uk ? Many thanks, John.
participants (5)
-
Ben Hutchings
-
David Abrahams
-
Edward Grace
-
John Maddock
-
João Abecasis