My first bug report, please let me know if I am missing anything.

Running...

$ cat minimal.cpp && echo "-----" && g++ -Wall minimal.cpp && a.out

Produces...

#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  map<const char*, int> hash;
  string sElement;

  sElement = "ab1";
  cout << sElement.c_str() << (( hash.find(sElement.c_str()) != hash.end() )
         ? "\t\tfound\n"
         : "\t\tnot found\n");

  sElement = "ab2";
  cout << sElement.c_str() << (( hash.find(sElement.c_str()) != hash.end() )
         ? "\t\tfound\n"
         : "\t\tnot found\n");


//  string aux = sElement;
  if( hash.find(sElement.c_str()) == hash.end() )
    hash[sElement.c_str()] = 7;

  sElement = "ab3";
  cout << sElement.c_str() << (( hash.find(sElement.c_str()) != hash.end() )
         ? "\t\tfound\n"
         : "\t\tnot found\n");

  return 0;
}
-----
ab1             not found
ab2             not found
ab3             found

There, the last line should be "ab3             not found", which can be
obtained by removing "//" from the only commented line.

$ cat /proc/version
Linux version 2.6.31-19-generic (bui...@palmer) (gcc version 4.4.1 (Ubuntu
4.4.1-4ubuntu8) ) #56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010

$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)


-- 
           Summary: map [] behaviour is inconsistent
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc_bugzilla dot 20 dot marcelitom at inboxclean dot com


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

Reply via email to