|
Boost : |
Subject: Re: [boost] Using allocator rebind on an incomplete type
From: David Abrahams (dave_at_[hidden])
Date: 2008-10-23 19:16:23
on Thu Oct 23 2008, Chris Newbold <Chris.Newbold-AT-mathworks.com> wrote:
> In trying to clean up some code in Boost.Pool, I've run afoul of some code in
> Microsoft's implementation of the STL where they are using allocator::rebind on an
> incomplete type. Something like this:
>
> struct Node; // Incomplete!
>
> template<typename T, typename Alloc>
> struct List
> {
> Alloc<T>::rebind<Node>::other::pointer node_p;
> ...
> }
>
> I believe that attempting to instantiate an allocator with an
> incomplete type is illegal
Attempting to instantiate any library-defined template on an incomplete
type (I think shared_ptr is the one exception to this rule now) induces
undefined behavior.
Thus, std::allocator<T>::rebind<X> on an incomplete X induces undefined
behavior when a user does it. The library might know enough about
std::allocator to do it anyway, though.
It doesn't mean that instantiating any old template whose instances
model Allocator on an incomplete type is illegal, though.
> so, by extension, I would have assumed that attempting to rebind on an
> incomplete type would also be illegal, no?
I don't think that's strictly illegal -- at least not by the rule you
are alluding to. It depends on what the Allocator requirements say.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk