This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/2694: signedness warning in __advance
- To: gcc-gnats at gcc dot gnu dot org
- Subject: libstdc++/2694: signedness warning in __advance
- From: wolfgang dot bangerth at iwr dot uni-heidelberg dot de
- Date: 30 Apr 2001 11:55:11 -0000
- Reply-To: wolfgang dot bangerth at iwr dot uni-heidelberg dot de
>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: