Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-07-13 06:44:35

> These tricks work for GCC
> 2.95.2, but I've been unable to get them to work with MSVC6.
> I think there might be trouble with Borland, though.

Is it MSVC or STLport? I removed all the #ifdefs so that it
was using your new method always and I found:

1. It worked fine with both Borland compilers I use, and did
   indeed eliminate the warnings, although so does a simple
   #pragma warn -8012

2. MSVC didn't generate any warnings until I bumped the warning
   level up to 4, and then your change worked fine and did
   reduce the cast_test.cpp warnings from 55 down to 47.

3. It wouldn't work with GCC 2.95.2 at all due to a lack of

4. When I added the following test

    caught_exception = false;
    try { numeric_cast<unsigned
short>( std::numeric_limits<long>::max() ); }
    catch (bad_numeric_cast)
        { cout<<"caught bad_numeric_cast #6\n"; caught_exception = true; }
    if ( !caught_exception ) ++err_count;

   It failed (didn't throw). That's because I don't think the
   last test is correct:

    template <>
    struct greater_than_type_max<false>
        template <class X, class Y>
        static bool check(X x, Y)
            { return x >= 0 && static_cast<X>(static_cast<Y>(x)) == x; }

   This seems to be checking that it didn't overflow rather than
   that it would. So the following test also failed

    caught_exception = false;
    try { numeric_cast<unsigned
long>( std::numeric_limits<short>::max() ); }
    catch (bad_numeric_cast)
        { cout<<"caught bad_numeric_cast #7\n"; caught_exception = true; }
    if ( caught_exception ) ++err_count;

   (It threw and shouldn't have)

> Comments welcome!

I always think it is worthwhile to eliminate warnings by doing
the right thing rather than simply suppressing them with a
#pragma, so keep it up.


Boost list run by bdawes at, gregod at, cpdaniel at, john at