This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: semantics of attribute const on constructors
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Matthias Kretz <kretz at compeng dot uni-frankfurt dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 25 Feb 2011 16:26:24 +0100
- Subject: Re: semantics of attribute const on constructors
- References: <201102251619.22610.kretz@compeng.uni-frankfurt.de>
On Fri, Feb 25, 2011 at 4:19 PM, Matthias Kretz
<kretz@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
>