public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/23632] New: std::vector<bool> in combination with debug mode fails to compile code
@ 2005-08-30 11:54 fischerk at inf dot ethz dot ch
  2005-08-30 11:55 ` [Bug libstdc++/23632] " fischerk at inf dot ethz dot ch
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fischerk at inf dot ethz dot ch @ 2005-08-30 11:54 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-09-07 10:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-30 11:54 [Bug libstdc++/23632] New: std::vector<bool> in combination with debug mode fails to compile code fischerk at inf dot ethz dot ch
2005-08-30 11:55 ` [Bug libstdc++/23632] " fischerk at inf dot ethz dot ch
2005-08-30 12:26 ` fischerk at inf dot ethz dot ch
2005-08-30 14:34 ` pcarlini at suse dot de
2005-08-30 14:38 ` fischerk at inf dot ethz dot ch
2005-08-30 15:03 ` pcarlini at suse dot de
2005-08-31 17:23 ` cvs-commit at gcc dot gnu dot org
2005-08-31 19:18 ` pcarlini at suse dot de
2005-09-07 10:24 ` pcarlini at suse dot de

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).