Opened 8 years ago

Closed 8 years ago

#11141 closed Bugs (invalid)

boost::noncopyable does not prevent adding copy constructor to derived class

Reported by: Andreas Fenkart <afenkart@…> Owned by: No-Maintainer
Milestone: To Be Determined Component: utility
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc: michael.tross@…

Description

The documentation from boost::noncopyable is quite minimal. http://www.boost.org/doc/libs/1_55_0/libs/utility/utility.htm#Class_noncopyable http://stackoverflow.com/questions/7823990/what-are-the-advantages-of-boostnoncopyable

To my understanding the attached code shouldn't compile

$ gcc --version gcc (Debian 4.9.2-10) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Attachments (2)

test_noncopyable.cpp (525 bytes ) - added by Andreas Fenkart <afenkart@…> 8 years ago.
class deriving boost::noncopyable and declaring copy constructor
test_noncopyable2.cpp (335 bytes ) - added by Andreas Fenkart <afenkart@…> 8 years ago.
boost::noncopyable correctly working

Download all attachments as: .zip

Change History (6)

by Andreas Fenkart <afenkart@…>, 8 years ago

Attachment: test_noncopyable.cpp added

class deriving boost::noncopyable and declaring copy constructor

comment:1 by viboes, 8 years ago

Component: Noneutility
Owner: set to No-Maintainer

comment:2 by Marshall Clow, 8 years ago

My opinion on this is "close as not a bug".

We don't prevent people from acting maliciously.

noncopyable makes the copy constructor and assignment operators private (and doesn't implement them), so if you call them you get a compile (or link) error. If you go and implement your own copy constructor in a class that is derived from noncopyable, then my belief is that you wanted to be able to copy those objects.

comment:3 by Andreas Fenkart <afenkart@…>, 8 years ago

Yup, seems I got the semantics wrong, boost::noncopyable is a macro, that spares some typing. I still have to ensure Foo contains no copy constructor, I hoped it would free me from checking that as well.

I retire the question

by Andreas Fenkart <afenkart@…>, 8 years ago

Attachment: test_noncopyable2.cpp added

boost::noncopyable correctly working

comment:4 by Marshall Clow, 8 years ago

Resolution: invalid
Status: newclosed

Not really a macro - but a class that you inherit from to get certain behavior.

Because the behavior is inherited, you can override it if you choose.

Note: See TracTickets for help on using tickets.