[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: g++ behavior while noncopyable class

From: Miles Bader
Subject: Re: g++ behavior while noncopyable class
Date: Tue, 03 Apr 2012 10:18:28 +0900

Alex Vinokur <> writes:
> It is not my code. It is code of very large project.
> Actually I think we can't change 'return by value' to something else.
> It seems we need to remove 'noncopyable' for g++.
> What does standard of C++03 write of this?

My memory is the same as SG:  even if the copy is elided by
optimization, the class is still required to be "potentially copyable"
(in C++98/C++03).

I think many compilers were traditionally pretty lax, so source code
like this could slip through if the copy was not needed, but it was
always invalid.

Note that Clang (which, like recent versions of g++, does a pretty
good job of following the standard closely) gives the same error as

   $ clang++ -o uc -O2 error: base class 'noncopyable' has private copy constructor
   class Foo : private noncopyable
         ^ note: declared private here
         noncopyable( const noncopyable& );
         ^ note: implicit default copy constructor for 'Foo' first
         required here
           return Foo();
   1 error generated.


The secret to creativity is knowing how to hide your sources.
  --Albert Einstein

reply via email to

[Prev in Thread] Current Thread [Next in Thread]