There's a possible bug in the icc installed with Composer XE 2013 SP1 Update 5 (2013.1.5.239). The compiler compiiles the code but the result leads to a run-time crash.
Here is a c++ programs that can reproduce the crash:
If executed it leads to this error:
"Run-Time Check Failure #2 - Stack around the variable 'os_.1016' was corrupted."
//------------------------------------------------ #include <new> struct base { virtual ~base() {} }; struct test_type : virtual base { }; template<class T> struct opt { bool init_; char buffer_[sizeof(T)]; opt() : init_(false) {} void recreate() { clear(); construct(); } void clear() { if (init_) { destroy(); } } ~opt() { clear(); } T& operator*() { return *address(); } private: void* raw_storage() { return &buffer_; } T* address() { return static_cast<T*>(raw_storage()); } void construct() { ::new (raw_storage()) T(); init_ = true; } void destroy() { address()->T::~T(); init_ = false; } }; void test() { opt<test_type>os_; os_.recreate(); os_.clear(); } int main() { test(); } //------------------------------------------------
The program compile and runs correctly in gcc, clang, and vc110. (Tried here: http://melpon.org/wandbox and in VS2012)