>Submitter-Id:  net-debian
>Originator:    Franck Branjonneau
>Organization:  
>Confidential:  no
>Synopsis:       No initialization of an int allocated with new int.
>Severity:       serious
>Priority:       medium
>Category:       c++
>Class:          wrong-code
>Release:       3.0 (Debian) (Debian testing/unstable)
>Environment:
System: Linux alpha.tchume.net 2.4.4 #2 mar mai 22 08:16:07 CEST 2001 i586 
unknown
Architecture: i586

        
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v 
--enable-languages=c,c++,java,f77,proto,objc --prefix=/usr 
--infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as 
--with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-x 
--without-included-gettext --disable-checking --enable-threads=posix 
--enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
>Description:
        
I compile the following code:

#include <iostream>

namespace utility {
  template< typename T, int role, bool ndebug >
  struct init {
    static T * do_it() { 
      T* tmp(new T);
      std::cout << "/tmp/ point to: " << *tmp << "\n";
      return tmp;
    }
  };


  template< typename T, int role, bool ndebug >
  struct exit {
    static void do_it(T * instance) { delete instance; }
  };
} // namespace utility

int main() {
  {
    int * tmp(utility::init< int, 1, true >::do_it());
    utility::exit< int, 1, true >::do_it(tmp);
  }
  int * tmp(utility::init< int, 0, true >::do_it());

}

got an executable and call it. The ouput was:

/tmp/ point to: 0
/tmp/ point to: 1075812784

>How-To-Repeat:
        
It's a context-dependant bug, so I don't know.
As an example, if I comment out utility::exit< int, 1, true >::do_it(tmp) in 
main(), the behavior is correct. 


>Fix:
        
Customize operator new() ;-)


Reply via email to