This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/9103: problems constructing from temporaries
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: <gcc-gnats at gcc dot gnu dot org>,<darryl dot green at unitab dot com dot au>,<gcc-bugs at gcc dot gnu dot org>,<nobody at gcc dot gnu dot org>,<gcc-prs at gcc dot gnu dot org>
- Date: Fri, 24 Jan 2003 17:11:38 +0100
- Subject: Re: c++/9103: problems constructing from temporaries
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
r=9103
Epurated test case:
-----------------------
struct A
{
A(const A& ) {}
A(A* ) {}
A( ) {}
void foo(void);
};
int main()
{
A a(A(A(new A())));
a.foo();
}
-----------------------
ice7.cpp: In function `int main()':
ice7.cpp:116: request for member `foo' in `a()', which is of non-aggregate
type
`A ()()'
This is on GCC 3.2. The above should clearly compile, since the line cannot
be a function declaration (because of the 'new' in it). GCC seems to be
confused because of the two temporaries, and you can see that also the
dumped type is wrong. If you remove one temporary:
A a(A(new A()));
the code compiles correctly. If you remove the 'new':
A a(A(A(A())));
the code fails as expected, but the error shows there is still some
confusion:
ice7.cpp:116: request for member `foo' in `a(A (*)(A (*)()))', which is of
non-aggregate type `A ()(A (*)(A (*)()))'
since it's missing the third function pointer (should be `A ()(A (*)(A (*)(A
(*)())))'.
For the original poster, I'd suggest using the alternative syntax A a =
A(whatever), unless the constructors are explicit.
Giovanni Bajo