From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19190 invoked by alias); 30 Aug 2005 11:53:13 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 19018 invoked by uid 48); 30 Aug 2005 11:52:58 -0000 Date: Tue, 30 Aug 2005 11:54:00 -0000 From: "fischerk at inf dot ethz dot ch" To: gcc-bugs@gcc.gnu.org Message-ID: <20050830115242.23632.fischerk@inf.ethz.ch> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libstdc++/23632] New: std::vector in combination with debug mode fails to compile code X-Bugzilla-Reason: CC X-SW-Source: 2005-08/txt/msg03437.txt.bz2 List-Id: 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 int main(int,char **) { std::vector v(100); const std::vector::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 >]': 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 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