This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/3827: new int problem.



>Number:         3827
>Category:       c++
>Synopsis:       No initialization of an int allocated with new int.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 25 17:36:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Franck Branjonneau
>Release:        3.0 (Debian) (Debian testing/unstable)
>Organization:
>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() ;-)
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]