Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #15188

Re: g++ behavior while noncopyable class

From Miles Bader <miles@gnu.org>
Newsgroups comp.lang.c++, gnu.g++.help
Subject Re: g++ behavior while noncopyable class
Date 2012-04-03 10:18 +0900
Message-ID <87wr5x62aj.fsf@catnip.gol.com> (permalink)
References <7d36f4e9-f87e-47c5-be20-3e80e1063323@v2g2000vbx.googlegroups.com> <8c8a6fd5-ba3e-41db-aaa9-6c3749b96a46@db5g2000vbb.googlegroups.com> <4698fe3a-db2f-45f2-b4df-68fbfd8c1d3a@er9g2000vbb.googlegroups.com> <0962750e-94d5-4357-9e95-3b4f5cc4d7f2@i18g2000vbx.googlegroups.com>

Cross-posted to 2 groups.

Show all headers | View raw


Alex Vinokur <alex.vinokur@gmail.com> 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
g++:

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

-miles

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

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

g++ behavior while noncopyable class Alex Vinokur <alex.vinokur@gmail.com> - 2012-03-28 01:24 -0700
  Re: g++ behavior while noncopyable class Alex Vinokur <alex.vinokur@gmail.com> - 2012-03-28 02:05 -0700
    Re: g++ behavior while noncopyable class Alex Vinokur <alex.vinokur@gmail.com> - 2012-03-28 11:13 -0700
      Re: g++ behavior while noncopyable class Miles Bader <miles@gnu.org> - 2012-04-03 10:18 +0900
    Re: g++ behavior while noncopyable class SG <s.gesemann@gmail.com> - 2012-03-28 10:21 -0700
  Re: g++ behavior while noncopyable class Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-03 10:36 +0000

csiph-web