Hi
This bit me today, when I realized that I had written a bit of code that shouldn't compile, but did.
Consider the following program:
class Copyable { }; class NonCopyable { NonCopyable(const NonCopyable&) {} NonCopyable& operator= (const NonCopyable&) { return *this; } public: NonCopyable() {} NonCopyable(const Copyable&) {} NonCopyable& operator= (const Copyable&) { return *this; } Copyable move() { return Copyable(); } }; Copyable function(NonCopyable nc) { return nc.move(); } int main() { NonCopyable nc1; NonCopyable nc2( function( nc1.move() ) ); }
For this program, the 7.4.x C6000 compiler correctly complains that
"../temporary.cpp", line 21: error #694-D: "NonCopyable::NonCopyable(const NonCopyable &)", required for copy that was eliminated, is inaccessible
However, if I use a non-copyable base class (like boost::noncopyable), i.e.
class NonCopyableBase { NonCopyableBase(const NonCopyableBase&) {} NonCopyableBase& operator= (const NonCopyableBase&) { return *this; } protected: NonCopyableBase() {} }; class Copyable { }; class NonCopyable : private NonCopyableBase { public: NonCopyable() {} NonCopyable(const Copyable&) {} NonCopyable& operator= (const Copyable&) { return *this; } Copyable move() { return Copyable(); } }; Copyable function(NonCopyable nc) { return nc.move(); } int main() { NonCopyable nc1; NonCopyable nc2( function( nc1.move() ) ); }
then the code is compiled without any warning or error. The 8.x branch behaves differently and correctly complains in both cases.
The compiler flags were
-mv6400 --abi=coffabi -O3 -ms3 --strict_ansi --rtti
Unless I'm wrong and a diagnostic isn't required, is there any chance that this will be fixed in a future release of the 7.4.x branch (at least with --strict_ansi)?
Markus