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: Alex Vinokur
Subject: Re: g++ behavior while noncopyable class
Date: Wed, 28 Mar 2012 11:13:57 -0700 (PDT)
User-agent: G2/1.0

Thank you.

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?

Alex

On Mar 28, 7:21 pm, SG <s.gesem...@gmail.com> wrote:
> 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]