This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/23632] New: std::vector<bool> in combination with debug mode fails to compile code
- From: "fischerk at inf dot ethz dot ch" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Aug 2005 11:52:58 -0000
- Subject: [Bug libstdc++/23632] New: std::vector<bool> in combination with debug mode fails to compile code
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Dear libstdc++ coders,
I think I discovered a bug in the debug mode of gcc-4.0.0. It is the following program that should
compile using the debug mode but that does not.
// BEGIN
#include <vector>
int main(int,char **)
{
std::vector<bool> v(100);
const std::vector<bool>::const_iterator fu = v.begin();
if (fu[4])
;
}
// END
If I compile it via
/Users/hbf/sw/gcc-4.0.0/bin/g++ -v -save-temps -D_GLIBCXX_DEBUG test2.C -o test2
then I obtain the following output:
// BEGIN OUTPUT
Using built-in specs.
Target: powerpc-apple-darwin8.1.0
Configured with: ../gcc-4.0.0/configure --prefix=/Users/hbf/sw/gcc-4.0.0 --enable-languages=c++
Thread model: posix
gcc version 4.0.0
/Users/hbf/sw/gcc-4.0.0/libexec/gcc/powerpc-apple-darwin8.1.0/4.0.0/cc1plus -E -quiet -v -
D__DYNAMIC__ -D__APPLE_CC__=1 -D_GLIBCXX_DEBUG test2.C -fPIC -fpch-preprocess -o test2.ii
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/Users/hbf/sw/gcc-4.0.0/lib/gcc/powerpc-apple-
darwin8.1.0/4.0.0/../../../../powerpc-apple-darwin8.1.0/include"
#include "..." search starts here:
#include <...> search starts here:
/Users/hbf/sw/gcc-4.0.0/lib/gcc/powerpc-apple-darwin8.1.0/4.0.0/../../../../include/c++/4.0.0
/Users/hbf/sw/gcc-4.0.0/lib/gcc/powerpc-apple-darwin8.1.0/4.0.0/../../../../include/c++/4.0.0/
powerpc-apple-darwin8.1.0
/Users/hbf/sw/gcc-4.0.0/lib/gcc/powerpc-apple-darwin8.1.0/4.0.0/../../../../include/c++/4.0.0/
backward
/Users/hbf/sw/gcc-4.0.0/include
/Users/hbf/sw/gcc-4.0.0/lib/gcc/powerpc-apple-darwin8.1.0/4.0.0/include
/usr/include
/System/Library/Frameworks
/Library/Frameworks
End of search list.
/Users/hbf/sw/gcc-4.0.0/libexec/gcc/powerpc-apple-darwin8.1.0/4.0.0/cc1plus -fpreprocessed
test2.ii -fPIC -quiet -dumpbase test2.C -auxbase test2 -version -o test2.s
GNU C++ version 4.0.0 (powerpc-apple-darwin8.1.0)
compiled by GNU C version 4.0.0.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
/Users/hbf/sw/gcc-4.0.0/lib/gcc/powerpc-apple-darwin8.1.0/4.0.0/../../../../include/c++/4.0.0/
debug/safe_iterator.h: In member function 'typename std::iterator_traits<_Iterator>::reference
__gnu_debug::_Safe_iterator<_Iterator, _Sequence>::operator[](const typename
std::iterator_traits<_Iterator>::difference_type&) const [with _Iterator =
__gnu_norm::_Bit_const_iterator, _Sequence = __gnu_debug_def::vector<bool, std::allocator<bool> >]':
test2.C:7: instantiated from here
/Users/hbf/sw/gcc-4.0.0/lib/gcc/powerpc-apple-darwin8.1.0/4.0.0/../../../../include/c++/4.0.0/
debug/safe_iterator.h:270: error: passing 'const __gnu_norm::_Bit_const_iterator' as 'this' argument of
'bool __gnu_norm::_Bit_const_iterator::operator[](ptrdiff_t)' discards qualifiers
// END OUTPUT
I will attach the test2.s and test2.ii files for the above call.
Could it be that in order to fix this, you have to add to class _Bit_const_iterator an "operator[] const"?
Currently, _Bit_const_iterator only provides a non-const member "operator[]". If I add in file gcc-4.0.0/
include/c++/4.0.0/bits/stl_bvector.h after line 345:
const_reference
operator[](difference_type __i) const // Note: it is const.
{ return *(*this + __i); }
Then the above code compiles fine.
Thanks for your work!
Kaspar
--
Summary: std::vector<bool> in combination with debug mode fails
to compile code
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fischerk at inf dot ethz dot ch
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: Using built-in specs.
GCC host triplet: powerpc-apple-darwin8.1.0
GCC target triplet: powerpc-apple-darwin8.1.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23632