Article View: gnu.g++.bug
Article #235constructors not called on new'ed array elements
From: Doug Moore
Date: Sun, 12 Apr 1992 03:53
Date: Sun, 12 Apr 1992 03:53
50 lines
1899 bytes
1899 bytes
GNU C++ compiler version 2.1, with Tiemann and Stump patches. Sunos
4.1. Sparc 2. The program below prints
i = 1 (should be 5).
It demonstrates a bug. The foo constructor is called only on the
first element of the array foo::array, not on all the elements as it
should be.
Thanks to Mark Wells for isolating this bug nicely.
Doug Moore
(dougm@cs.rice.edu)
Compiler output:
c++ -g -v -Wall wells.cc
Reading specs from /marsh/comp212/lib/gcc-lib/sun4/2.1/specs
gcc version 2.1
/marsh/comp212/lib/gcc-lib/sun4/2.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g -Wall wells.cc /usr/tmp/cca06635.i
GNU CPP version 2.1 (sparc)
/marsh/comp212/lib/gcc-lib/sun4/2.1/cc1plus /usr/tmp/cca06635.i -quiet -dumpbase wells.cc -g -Wall -version -o /usr/tmp/cca06635.s
GNU C++ version 2.1 (sparc) compiled by GNU C version 2.1.
as -o wells.o /usr/tmp/cca06635.s
/marsh/comp212/lib/gcc-lib/sun4/2.1/ld -e start -dc -dp /lib/crt0.o -L/marsh/comp212/lib/gcc-lib/sun4/2.1/ -L/marsh/comp212/lib/ wells.o -lg++ -lm -lgcc -lc -lg -lgcc
Compilation finished at Sat Apr 11 22:47:49
Source code:
----------------cut here--------------------------------------------
#include <stream.h>
int i = 0;
class foo
{
private:
static foo *array;
public:
foo()
{
i++;
}
};
foo* foo::array = new foo [5];
main()
{
cerr << "i = " << i << " (should be 5).\n";
}
Technical Details
Message-ID:
<9204120353.AA06266@cs.rice.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougmShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.rice.edu!dougm From: dougm@cs.rice.edu (Doug Moore) Subject: constructors not called on new'ed array elements Message-ID: <9204120353.AA06266@cs.rice.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Sun, 12 Apr 1992 03:53:35 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 52