This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -Wconversion versus libstdc++


On Wed, Jan 17, 2007 at 04:36:04PM -0600, Gabriel Dos Reis wrote:
> I just built firefox (CVS) with GCC mainline.  The compiler spitted
> avalanches of non-sensical warning about conversions signed ->
> unsigned may alter values, when in fact the compiler knows that
> such things cannot happen.
> 
> First, let's recall that GCC supports only 2s complement targets.
> 
> Second, a conversion from T to U may alter value if a round trip is
> not the identity function.  That is, there exists a value t in T
> such that the assertion
> 
>    assert (T(U(t)) == t)
> 
> fails.
> 
> Now, given a signed integer type T, and U as unsigned variant, there
> is no way the above can happen, given the characteristics of GCC.
> There many of this "may alter value" business is pure noise.

Careful.  As you suggest, let's restrict ourselves to two's complement
platforms.  I would want the compiler to warn if the identity holds for an
ILP32 machine but not an LP64 machine, even if I'm running on an ILP32.
But if the two types are going to be the same size everywhere (because one
is the unsigned modifier of the other) then GCC should not complain.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]