help-gplusplus
[Top][All Lists]
Advanced

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

Re: g++ behavior while noncopyable class


From: SG
Subject: Re: g++ behavior while noncopyable class
Date: Wed, 28 Mar 2012 10:21:40 -0700 (PDT)
User-agent: G2/1.0

On 28 Mrz., 11:05, Alex Vinokur wrote:
> On Mar 28, 10:24 am, Alex Vinokur wrote:
>
> > While compiling program below, behavior of g++ differs from Intel and
> > aCC HP compilers.
> > g++ detects error.
>
> > Any suggestions?

Yes: Write legal C++ code.

If you want a function to return an object of your class by value, you
better make this class at least movable. The other compilers probably
complain because they simply don't care and just apply copy elision.
However, the standard requires the class to be at least movable (C+
+2011) or copyable (C++2003) regardless of wether a compiler does RVO
or not (RVO = return value optimization).

> The same problem with simpler program.
>
> class noncopyable
> {
>    protected:
>       noncopyable() {}
>       ~noncopyable() {}
>    private:
>       noncopyable( const noncopyable& );
>       const noncopyable& operator=( const noncopyable& );
> };
>
> class Foo : private noncopyable
> {
>         public:
>         Foo (){}
> };
>
> Foo func1()
> {
>         return Foo();
> }
>
> [...]

Cheers!
SG


reply via email to

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