|
Boost Users : |
From: Erik (esigra_at_[hidden])
Date: 2008-03-18 11:05:09
Nat Goodspeed skrev:
> Erik wrote:
>
>> John Maddock skrev:
>>
>>> Erik wrote:
>>>
>>>
>>>> We have this really neat and simple macro in our project:
>>>> #define compile_assert(x) typedef bool COMPILE_ASSERT[(x) ? 1 : -1]
>>>>
>>>> Although it does what we need and serves us well, I tried to replace
>>>> it with BOOST_STATIC_ASSERT. Unfortunately this resulted in a lot of
>>>> ugly warnings throughout the compile:
>>>> warning: use of old-style cast
>>>>
>>>>
>>> Which compiler is this?
>>>
>>>
>> g++ (with the parameter -Wold-style-cast)
>>
>
> I bet he's going to ask you which version of g++ you're using. Behavior
> can vary widely across versions.
I do not think so. An old-style-cast is a well-defined thing and all
versions of g++ that has -Wold-style-cast should catch them. The only
thing that varies between versions is that g++-4.2 and later also have
-Werror=old-style-cast.
Note: This is what the creator of C++ has to say about old-style-cast:
«From C, C++ inherited the notation (T) e, which performs any conversion
that can be expressed as a combination of static_casts,
reinterpret_casts, and const_casts to make a value of type T from the
expression e (§B.2.3). This C-style cast is far more dangerous than the
named conversion operators because the notation is harder to spot in a
large program and the kind of conversion intended by the programmer is
not explicit. That is, (T) e might be doing a portable conversion
between related types, a nonportable conversion between unrelated types,
or removing the const modifier from a pointer type. Without knowing the
exact types of T and e, you cannot tell.» (Stroustrup, 2000)
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net