The problem can be reproduced even more simply:

BOOST_STATIC_WARNING(false);

does not produce a warning on my machine.

If I make my own (not as versatile) version, which mimics the way Boost actually does it without all the MPL stuff, it works:

namespace detail
{
    template <typename TIntegralContant>
    inline void test_warning(const TIntegralContant&)
    {
        static_cast<void>(1 / TIntegralContant::value);
    }
}

#define MY_STATIC_WARNING(value_) \
    ::detail::test_warning(::boost::integral_constant<bool, value_ >())

So it isn't that g++ won't emit a warning for that error, it just seems to get lost somewhere.

On Wed, May 25, 2011 at 1:16 PM, Ovanes Markarian <om_boost@keywallet.com> wrote:


On Wed, May 25, 2011 at 7:09 PM, Travis Gockel <travis@gockelhut.com> wrote:
I've recently had some trouble with C++'s implicit casting, so I'm looking for a way to warn people if somebody attempts to assign an int32_t to a uint64_t or whatever.  BOOST_STATIC_ASSERT would work wonders for this, except that the code base I'm working with is quite large and relies on a lot of implicit casting, so immediately breaking everything with assertions is unrealistic.

It looks like BOOST_STATIC_WARNING (http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/static_warning.html) would be ideal for me, however, I cannot get it to actually emit a warning.  I have attached a quick example of what I am looking for, but it essentially boils down to this not doing anything:

        typedef boost::is_same<int64_t, int32_t> same_type;
        BOOST_STATIC_WARNING(same_type::value);

My compiler is g++ 4.4.3 with --std=c++0x -Wall -Wextra.

Thanks!

Hello Travis,

unfortunately I have no boost 1.46 by the hand, but as far as I understand int64_t and int32_t are different type and should not result in value equals true. What happens if you produce non-convertible types like:

template<class T> identity{}; //you can also use mpl::identity

typedef boost::is_same<identity<int64_t>, identity<int32_t> > same_type;

BOOST_STATIC_WARNING(same_type::value);


With Kind Regards,
Ovanes



 

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



--
- Travis Gockel