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++


Paolo Carlini <pcarlini@suse.de> writes:

| Joe Buck wrote:
| 
| >In the case of the containers, we are asserting/relying on the fact that
| >the pointer difference is zero or positive.  But this has become a
| >widespread idiom: people write their own code in the STL style.  If STL
| >code now has to be fixed to silence warnings, so will a lot of user code.
| >
| Good point. About it, we should also take into account the recent
| messages from Martin, pointing out that many C++ front-ends do not
| warn for signed -> unsigned.

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.

The function responsible for that diagnostic should be refined.

-- Gaby


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