This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14603] New: constructors within constructor fails
- From: "bjorn at fiskbil dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Mar 2004 13:14:44 -0000
- Subject: [Bug c++/14603] New: constructors within constructor fails
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When trying to call a constructor with two constructors, the two constructors
are called with indexed arrays, in it g++ refuses to compile it. It works if I
create variables outside of the first constructor and pass them in. Instead of
rambling I'll just show you the code and the errors.
class Vector {
public:
Vector() {}
Vector(float x, float y, float z) { coords[0]=x; coords[1]=y; coords[2]=z; }
private:
float coords[3];
};
class Model {
public:
Model() {}
Model(const Vector &m, const Vector &n) { M=m; N=n; }
private:
Vector M, N;
};
int main(int argc, char **argv) {
float v1[3], v2[3];
Model m(Vector(v1[0],v1[1],v1[2]), Vector(v2[0],v2[1],v2[2]));
return 0;
}
And the output from g++ -v -save-temps testcase.cpp is this:
# g++ -v -save-temps testcase.cppu
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,ob
jc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib -
-enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gn
u --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib,gtk --enable-objc
-gc i486-linux
Thread model: posix
gcc version 3.3.3 (Debian 20040314)
/usr/lib/gcc-lib/i486-linux/3.3.3/cc1plus -E -D__GNUG__=3 -quiet -v -D__GNUC__=
3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -D_GNU_SOURCE testcase.cpp testcase
.ii
ignoring nonexistent directory "/usr/i486-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.3
/usr/include/c++/3.3/i486-linux
/usr/include/c++/3.3/backward
/usr/local/include
/usr/lib/gcc-lib/i486-linux/3.3.3/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i486-linux/3.3.3/cc1plus -fpreprocessed testcase.ii -quiet -du
mpbase testcase.cpp -auxbase testcase -version -o testcase.s
GNU C++ version 3.3.3 (Debian 20040314) (i486-linux)
compiled by GNU C version 3.3.3 (Debian 20040314).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64354
testcase.cpp: In function `int main(int, char**)':
testcase.cpp:29: error: parse error before `,' token
testcase.cpp:29: error: no matching function for call to `Model::Model(float&,
float&, float&)'
testcase.cpp:12: error: candidates are: Model::Model(const Model&)
testcase.cpp:15: error: Model::Model(const Vector&, const
Vector&)
testcase.cpp:14: error: Model::Model()
testcase.cpp:29: error: parse error before `)' token
This is on debian unstable with gcc 3.3.3
The same error occurs on a Red Hat 8.0 gcc 3.2 box.
Lines such as this one works though
float v1x, v1y, v1z;
Model m(Vector(v1x,v1y,v1z), Vector(v2[0],v2[1],v2[2]));
or this one
Vector v(v1[0], v1[1], v2[2]);
Model m(v, Vector(v2[0],v2[1],v2[2]));
--
Summary: constructors within constructor fails
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bjorn at fiskbil dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14603