Uhm, if I'm not confused, it is reasonable that the copy constructor is not called. Do you expect the Ivar to be magically destroyed and replicated? I assume against C ++ rules. If the synthesized setter is conceptual
-(void)setFoo:(Foo)foo_{ foo=foo_; }
then operator= should be called, not the copy constructor.
At the same time , operator= also not called bummer (10.6.4, gcc 4.2.1.)! Here is an example code:
Save it in boo.mm , I had:
$ g++ -fobjc-call-cxx-cdtors boo.mm -framework Foundation $ ./a.out 2010-09-04 12:32:06.570 a.out[24352:903] default constructor for 0x10010cdc8 2010-09-04 12:32:06.572 a.out[24352:903] default constructor for 0x7fff5fbff7e0 2010-09-04 12:32:06.573 a.out[24352:903] copy constructor for 0x7fff5fbff7d0 $
Now I had an explicit installer, which I wrote above, instead of @synthesize Foo , I correctly had
$ ./a.out 2010-09-04 12:42:22.206 a.out[24417:903] default constructor for 0x10010cdc8 2010-09-04 12:42:22.209 a.out[24417:903] default constructor for 0x7fff5fbff7e0 2010-09-04 12:42:22.210 a.out[24417:903] copy constructor for 0x7fff5fbff7d0 2010-09-04 12:42:22.210 a.out[24417:903] assignment operator for 0x10010cdc8
Clan source code for generating this synthesized setter, see GenerateObjCSetter . There, he eventually checks to see if the C ++ assignment operator is needed. I would say that this is a gray area, not well documented, but is currently being implemented ...
source share