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: | 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)
Change History (6)
by , 8 years ago
Attachment: | test_noncopyable.cpp added |
---|
comment:1 by , 8 years ago
Component: | None → utility |
---|---|
Owner: | set to |
comment:2 by , 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 , 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
comment:4 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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.
class deriving boost::noncopyable and declaring copy constructor