[Bug libstdc++/23632] New: std::vector in combination with debug mode fails to compile code

2005-08-30 Thread fischerk at inf dot ethz dot ch
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


[Bug libstdc++/23632] std::vector in combination with debug mode fails to compile code

2005-08-30 Thread fischerk at inf dot ethz dot ch

--- Additional Comments From fischerk at inf dot ethz dot ch  2005-08-30 
11:54 ---
Created an attachment (id=9620)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9620&action=view)
ii-output from g++ -v -save-temps


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23632


[Bug libstdc++/23632] std::vector in combination with debug mode fails to compile code

2005-08-30 Thread fischerk at inf dot ethz dot ch

--- Additional Comments From fischerk at inf dot ethz dot ch  2005-08-30 
11:55 ---
Created an attachment (id=9621)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9621&action=view)
s-output from g++ -v -save-temps


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23632


[Bug libstdc++/23632] std::vector in combination with debug mode fails to compile code

2005-08-30 Thread fischerk at inf dot ethz dot ch

--- Additional Comments From fischerk at inf dot ethz dot ch  2005-08-30 
14:37 ---
Sorry, my mistake, the code is sent was not the right one. (I tested around and 
did not realize that I 
sent the wrong one, sorry.) Here is the code that causes the problem; and it 
only happens when I 
compile using the debug mode:

// BEGIN
#include 

int main(int,char **)
{
  std::vector v(100);
  std::vector::const_iterator fu = v.begin(); // no const in front of the 
line
  if (fu[4])
;
}
// END

Tell me if you again need the .ii and .s-files.

Sorry for the confusion.
Kaspar

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23632