c++/9103: problems constructing from temporaries
Giovanni Bajo
giovannibajo@libero.it
Fri Jan 24 16:27:00 GMT 2003
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
More information about the Gcc-bugs
mailing list