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 Gaby,
| 
| >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.
| >
| First, I want to tell you that I agree with your general point of
| view, here and elsewhere, in particular about the tension existing
| between difference_type and size_type: as a matter of fact, when, time
| ago, I noticed some differences between our vector and deque
| implementations, I wrote something about it in private mail to Howard,
| but we didn't pursue the issue much...

I wasn't aware of that project.  We now have more incentive to puruse
it :-)

| Coming to the specific issue, and *assuming* we agree about the
| usefulness of warning for signed -> unsigned, maybe we are "lucky", in
| this sense: Table 65 says *explicitely* that size_type can represent
| any non-negative value of difference_type. Thus, as I see the issue,
| we can safely cast from the latter to the former, if we want, without
| entering in the larger discussions mentioned above... What do you
| think?

My concern is for vectors whose size() exceeds
numeric_limits<difference_type>::max() -- even if we would like to avoid 
the general discussion. 

My understanding -- and I would like to hear of others' -- is that the
semantics description in the table 65 is a constraint on
implementations.  Concretely, it means that we cannot have a vector 
whose size() is numeric_limits<size_type>::max() because otherwise
the difference between end() and begin() will overflow.
That implies that max_size() would have to return 
numeric_limit<difference_type>::max().

-- Gaby


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