This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]