Steven Watanabe wrote:
AMDG
Yang Zhang wrote:
Hi, I can't figure out how to properly use noncopyable. I'm always
getting things like "has a non-virtual destructor" warnings.
Do you have a simple test case?
$ cat noncopyable.cc
#include
using namespace boost;
class C : noncopyable {};
int main() { return 0; }
$ g++ -Wall -g3 -o noncopyable noncopyable.cc -Wextra -Wconversion
-Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Winit-self
-Wno-unused-parameter -Wparentheses -Wmissing-format-attribute
-Wfloat-equal -Winline -Woverloaded-virtual -Wsign-promo -Wc++0x-compat
-Wsynth -Wall -Werror -Wextra -Weffc++ -Wstrict-null-sentinel
-Wno-old-style-cast -Woverloaded-virtual -Wsign-promo -Wformat=2
-Winit-self -Wswitch-enum -Wunused -Wstrict-overflow -Wfloat-equal
-Wundef -Wunsafe-loop-optimizations -Wpointer-arith -Wcast-qual
-Wcast-align -Wwrite-strings -Wconversion -Wlogical-op
-Wno-aggregate-return -Wno-missing-declarations
-Wno-missing-field-initializers -Wmissing-noreturn
-Wmissing-format-attribute -Wpacked -Wredundant-decls -Wunreachable-code
-Winline -Winvalid-pch -Wlong-long -Wvolatile-register-var -Wstack-protector
cc1plus: warnings being treated as errors
noncopyable.cc:3: error: base class âclass
boost::noncopyable_::noncopyableâ has a non-virtual destructor
I understand that this shouldn't be a problem as noncopyable is not
meant to be used directly as any variable's static type, but I do
require enabling this warning.
I currently use the following simple macro:
/** For use within a type definition. Makes the type non-copyable. */
#define NONCOPYABLE(type) \
private: \
type(const type&); \
void operator=(const type&);
In fact,
compiling noncopyable_test.cpp gives me:
<snip error message>
Any hints? Thanks in advance.
noncopyable_test.cpp isn't supposed to compile. Did you read the comment?
// This program demonstrates compiler errors resulting from trying to copy
// construct or copy assign a class object derived from class noncopyable.
Sorry, I did not.
--
Yang Zhang
http://www.mit.edu/~y_z/