This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13481] No destuctor assumed in a forward declared class when being used in template


------- Additional Comments From giovannibajo at libero dot it  2003-12-24 02:49 -------
What you're trying to do is invalid under ANSI/ISO C++, so we can't possibily 
revert a bug we now fixed. Note also that deleting the pointer ("delete 
object") would be even worse, because if the type is incomplete, it leads to 
undefined behaviour (so everything can happen).

>From a technical point of view, when the compiler instantiates destruct(), it 
needs to know what the class looks like, because you're doing operator-> on it, 
so you're trying to access a member. You need Forward to be defined before 
isntantiating the template, that is before User.

You're trying to solve your problem in the wrong way. Instead of reinventing 
the wheel, use Boost's smart pointers, such as boost::shared_ptr or 
boost::scoped_ptr. They work very well with incomplete types, and they emit a 
compile time error if you try to destruct the object before completing the type 
(defining your forward-declared class), instead of leaving it to the undefined 
behaviour. They're going to be part of std:: anyway in the forthcoming C++ 
standard.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovannibajo at libero dot
                   |                            |it
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13481


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]