Subject: Re: [boost] [units] gcc warnings
From: Emil Dotchevski (emil_at_[hidden])
Date: 2010-06-15 19:12:32
On Tue, Jun 15, 2010 at 10:03 AM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> Humph. Has anyone in this discussion actually looked at the
> code in question?
> a) There can be no overflow because the possible values are enumerated.
> b) With the current code, the compiler will implicitly use a static_cast.
With the current code, the compiler will use an implicit conversion
which is not the same as static_cast in general. Casts are designed to
punch holes in the C/C++ type system, which by definition is a
dangerous thing to do. In contrast, one has to assume that implicit
conversions are a necessary, reasonably safe part of the language.
Integer implicit conversions specifically are very common in C and
C++. For example, incrementing a short int results in two implicit
conversions, one of which might lead to truncating the value. That is
about as safe (or unsafe) as the code in question, so why nobody cares
about that case? Answer: because the compiler doesn't warn.
If you don't want your compiler to issue a particular warning, a type
cast should be the last solution to reach for, IMO.
Reverge Studios, Inc.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk