This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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:

| Hi Manuel,
| 
| >> in a nutshell, what is happening is that a difference of two pointers is
| >> assigned to an unsigned variable. First blush, the warning seems to me a
| >> bit overzealous, but if we concur that this is what we *really* want for
| >> 4.3, we can change the affected (very old, indeed) lines of code, no
| >> problem at all.
| >
| > Hi Paolo,
| >
| > Wconversion is supposed to warn for conversions that may change a
| > value. Can the resulting value change when converted to unsigned? If
| > so, the warning is warranted (I think).
| >
| > Anyhow, Wconversion needs fine-tuning and I prefer for it to be useful
| > rather than to literally follow its definition, so if this operation
| > is quite frequent and safe, I could detect it and avoid the warning.
| >
| > I am no GCC or C++ expert, so please give me more information on the
| > issue and feedback from others would be appreciated.
| 
| Well, just have a look to Gerald' examples: it's old HP / SGI STL
| code, we are assigning / initializing a size_t from a pointer
| difference, or arithmetic, more generally. There are quite a few
| instances of the issue, beyond that pointed out by Gerald. Certainly,
| the HP / SGI engineers considered those assignment harmless, and I
| respect that kind of assessment, but on the other hand, at the time
| the compilers were probably weaker at warning, I'm not sure. All in
| all, I think we can definitely add casts to the library, would be only
| a few tens of lines worth of patch, I think. Whether the warning is
| useful to the entire GCC community, I cannot say... But I hope we can
| resolve the issue rather quickly, because, in case, I'd like to start
| the audit of the library as soon as possible and be done with the
| issue as far as we are concerned...

There is something that we knoq about the code, that the compiler
does not have: we expect a sequence denoted by its first and last
element, so that the difference is always positive.  However, the
difference of pointers is defined in the language as an ptrdiff_t (a
signed type).  No wonder what people invented ssize_t :-)

I believe we have to investigate further what promises we want make
and hold through max_size() and change the code according to that.

-- Gaby


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