On Fri, Feb 25, 2011 at 4:19 PM, Matthias Kretz <kr...@compeng.uni-frankfurt.de> wrote: > Hi, > > what are the exact semantics of __attribute__((const)), when attached to a C++ > class constructor, supposed to be? > > My expectation was, that, since the ctor has a constructed object as return > value, the compiler is free, instead of calling a ctor twice for the case of > e.g. > Foo a(1); > Foo b(1); > , to do a memcopy of a to b after the a ctor is done. > > Instead the result of using __attribute__((const)) is, that GCC feels free to > optimize the whole ctor away. Apparently the ctor is treated as a function > that returns void.
If you lie to the compiler weird things will happen ;) > Do you rather want a bug report for the website documenting attribute const, > or for how GCC implements it? :-) None of the two. Richard. > Cheers, > Matthias > > -- > Dipl.-Phys. Matthias Kretz > http://compeng.uni-frankfurt.de/index.php?id=mkretz >