shared_ptr failure with undefined type (msvc)

Hi, I came to expect shared_ptr to handle undefined type, but here I got a test case (simplified from my use case) where it's actually breaks under msvc and works under gcc: #include "boost/shared_ptr.hpp" class UndefinedType; //// base class for template class FooBase{ public: virtual ~FooBase(); virtual void fff(); }; template <typename T> class Foo: public FooBase { public: virtual void fff() { // any virtual implementations seen are [have to be able to be] instantiated. This fails unless T is visible. x.reset(x.get()); } private: boost::shared_ptr<T> x; }; //// now use Foo as a field in a class class User { Foo<UndefinedType> y; }; It fails with: ...\boost-1.39\boost/checked_delete.hpp(32) : error C2027: use of undefined type 'UndefinedType' Is this expected to compile? Is this MSVC issue? Gennadiy

AMDG On 2/15/2011 9:35 AM, Gennadiy Rozental wrote:
I came to expect shared_ptr to handle undefined type, but here I got a test case (simplified from my use case) where it's actually breaks under msvc and works under gcc:
#include "boost/shared_ptr.hpp"
class UndefinedType;
//// base class for template class FooBase{ public: virtual ~FooBase();
virtual void fff(); };
template<typename T> class Foo: public FooBase { public: virtual void fff() { // any virtual implementations seen are [have to be able to be] instantiated. This fails unless T is visible. x.reset(x.get()); }
private: boost::shared_ptr<T> x; };
//// now use Foo as a field in a class class User { Foo<UndefinedType> y; };
It fails with:
...\boost-1.39\boost/checked_delete.hpp(32) : error C2027: use of undefined type 'UndefinedType'
Is this expected to compile? Is this MSVC issue?
Creating a shared_ptr from a raw pointer requires a complete type, unless you pass a deleter. MSVC must be instantiating Foo::fff sooner than gcc is. In Christ, Steven Watanabe
participants (2)
-
Gennadiy Rozental
-
Steven Watanabe