[PATH] fix broken mac build on old clangs.

Thiago Macieira thiago at macieira.org
Mon Nov 9 14:31:11 PST 2015


On Monday 09 November 2015 19:22:23 Tomaz Canabrava wrote:
> it deletes the Copy Constructor and the operator=, if you don't declare
> them the compiler will declare one anyhow. the way one does that in pre
> c++11 is to declare an empty  copy constructor and equal operator on the
> private area, but they are implemented by the constructor, only hard to
> reach.

The usual way is to declare them without bodies in the private area. If you 
declare them the way you proposed, you can still accidentally copy from the 
class itself and its friends and that usually produces hard-to-track errors at 
runtime.

C++98 error from non-friend:
<stdin>:1:13: error: ‘Foo::Foo(const Foo&)’ is private
<stdin>:1:98: error: within this context

C++98 from friend or inside the class:
:(.text+0x2b): undefined reference to `Foo::operator=(Foo const&)'

C++11 error:
<stdin>:1:135: error: use of deleted function ‘Foo& Foo::operator=(const 
Foo&)’
<stdin>:1:44: note: declared here

Another tiny but relevant difference is that GCC reports the first error on 
the function declared private, which is very confusing to people. Clang 
reports both on the point of use, like GCC did for the deleted function case.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358



More information about the subsurface mailing list