Suppose I have something like the following in test.cxx (and that I do the object slicing at 1 intentionally):
class A {
};
class B : public A {
// prevent copy construction and assignment
B(const B& other);
B& operator=(const B& other);
public:
explicit B(){}
};
class C {
A m_a;
public:
explicit C() : m_a( B() ) {} // 1
};
I expect this to work, as in 1 the copy-constructor of class A (here it is compiler-generated and public) should be called. This code also compiles fine on recent compilers (I tried g++-4.4 and Intel 11.0), however older compilers (such as g++-4.2 and g++-4.0) try to invoke the copy-constructor of B, which I declared to be private, resulting in:
test.cxx: In constructor ‘C::C()’: test.cxx:7: error: ‘B::B(const B&)’ is private test.cxx:16: error: within this context
Now, in my build-system I want to check whether the compiler supports above code. Question is, however, is this standard-conforming code? And what would be the proper name for such a test?
Edit: I'm sorry, Intel compiler version 10.1 and 11.0 both issue the following: warning #734: "B::B(const B &)" (declared at line 6), required for copy that was eliminated, is inaccessible