From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31348 invoked by alias); 18 Sep 2002 23:36:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 31331 invoked by uid 71); 18 Sep 2002 23:36:01 -0000 Date: Wed, 18 Sep 2002 16:36:00 -0000 Message-ID: <20020918233601.31330.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Phil Edwards Subject: Re: libstdc++/7972: > v.size(), where v is vector, incorrectly returns true Reply-To: Phil Edwards X-SW-Source: 2002-09/txt/msg00569.txt.bz2 List-Id: The following reply was made to PR libstdc++/7972; it has been noted by GNATS. From: Phil Edwards 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::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