public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/2694: signedness warning in __advance
@ 2001-04-30 4:56 wolfgang.bangerth
0 siblings, 0 replies; only message in thread
From: wolfgang.bangerth @ 2001-04-30 4:56 UTC (permalink / raw)
To: gcc-gnats
>Number: 2694
>Category: libstdc++
>Synopsis: signedness warning in __advance
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Apr 30 04:56:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Wolfgang Bangerth
>Release: unknown-1.0
>Organization:
>Environment:
gcc 3.0 20010423 prerelease
>Description:
When calling std::__advance(bidirectional_iterator) in some way
or other with an unsigned data type for _Distance, and using -W,
the compiler complains that >=0 is always satisfied. Two
ways to repeat the problem are to compile with -W the
following snippets:
------------------
#include <list>
void g() {
std::list<int>::iterator i;
std::advance (i, 1U);
};
-----------------
#include <vector>
#include <map>
void f() {
std::map<unsigned int, double> m;
std::vector<std::pair<unsigned int, double> > v;
v.insert (v.end(), m.begin(), m.end());
};
--------------------
The first gives the messages
tests/deal.II> ~/Config/gcc-ss-linux/bin/c++ -W -c a.cc
/home/atlas2/wolf/Config/gcc-ss-linux/include/g++-v3/bits/stl_iterator_base.h: In
function `void std::__advance(_BidirectionalIterator&, _Distance,
std::bidirectional_iterator_tag) [with _BidirectionalIterator =
std::_List_iterator<int, int&, int*>, _Distance = unsigned int]':
/home/atlas2/wolf/Config/gcc-ss-linux/include/g++-v3/bits/stl_iterator_base.h:356: instantiated from `void std::advance(_InputIterator&, _Distance) [with _InputIterator = std::_List_iterator<int, int&, int*>, _Distance = unsigned int]'
a.cc:4: instantiated from here
/home/atlas2/wolf/Config/gcc-ss-linux/include/g++-v3/bits/stl_iterator_base.h:336: warning: comparison
of unsigned expression >= 0 is always true
The second snippet has an even higher ugliness factor.
>How-To-Repeat:
Compile any of the code snippets above with -W
>Fix:
One would have to specialize the __advance(bidirectional_iterator)
function for signed and unsigned data types. Unfortunately,
the __type_traits class has no indicator telling us whether
a type is signed or not; however, the numeric_limits has
such a field and it could easily be casted to a class.
If someone gives me an indication on how to fix this problem,
I'd be happy to come up with a patch.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-04-30 4:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-30 4:56 libstdc++/2694: signedness warning in __advance wolfgang.bangerth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).