This is the mail archive of the gcc-prs@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: libstdc++/7972: > v.size(), where v is vector, incorrectly returns true


The following reply was made to PR libstdc++/7972; it has been noted by GNATS.

From: Phil Edwards <phil@jaj.com>
To: nathan.holladay@utsouthwestern.edu
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: libstdc++/7972: > v.size(), where v is vector, incorrectly returns true
Date: Wed, 18 Sep 2002 19:29:14 -0400

 On Wed, Sep 18, 2002 at 04:13:29PM -0000, nathan.holladay@utsouthwestern.edu wrote:
 > >Description:
 > (I am not sure about what the Submitter-Id is.)
 
 It's handled automatically if you use the normal bug reporting mechanisms.
 (And you did.)
 
 > It appears that a program will incorrectly return true at least for
 > an if statement, if(i > v.size()) where i is an integer of some value
 > less than the size of a vector, v. This exact same problem is found in
 > Microsoft's Visual C++ 6.0 compiler. I also reported it to them, and noted
 > the co-existence in the gnu compiler. (It is hard not to conclude that
 > someone copied from someone else,
 
 Faulty logic.  The only common code in this case is /yours/.  :-)
 
 
 > (I am suspecting that the '>' operator is simply overloaded improperly
 > for whatever type vector::size() returns.)
 
 There's no overloading.  The type involved will be something like
 "unsigned int".
 
     % g++-3.2 -Wall -W pr.cc
     pr.cc:8: warning: ISO C++ forbids declaration of `main' with no type
     pr.cc: In function `int main()':
 ->  pr.cc:14: warning: comparison between signed and unsigned integer expressions
     %
 
 Declare structnumber as "std::vector<double>::size_type" instead of int,
 and you won't have this problem.  (Yes, some typedefs will help you
 reducing typing.)
 
 
 Phil
 
 -- 
 I would therefore like to posit that computing's central challenge, viz. "How
 not to make a mess of it," has /not/ been met.
                                                  - Edsger Dijkstra, 1930-2002


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