ANSI C++ violation
Rene van Oostrum
rene@cs.ust.hk
Mon Feb 28 01:33:00 GMT 2000
The following message is a courtesy copy of an article
that has been posted to gnu.g++.bug as well.
The following code is happily compiled by g++ while it should report
an error:
class C {
int i_;
public:
C(int i) : i_(i) { }
};
int main(){
C* cp = new C[42](666);
return 0;
}
When an array of objects is created, one cannot pass arguments to the
constructors of those objects, no matter if the array is created on
the heap or not. See the Standard, 5.3.4, par 15.
One could argue that this is a useful extension, but in that case:
* it should be listed as such in the documentation;
* a warning should be issued when the -pedantic option is given to the
compiler
g++ -v says:
Reading specs from /usr/local/GNU/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/specs
gcc version 2.95.2 19991024 (release)
Regards,
Rene van Oostrum
More information about the Gcc-bugs
mailing list