Boost logo

Boost :

Subject: Re: [boost] [pimpl] Mini Review
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-26 16:24:37

Artyom Beilis wrote:
> From: Sergiu Dotenco <sergiu.dotenco_at_[hidden]>
> > Am 26.05.2011 18:28, schrieb Artyom Beilis:
> > >> From: Sergiu Dotenco <sergiu.dotenco_at_[hidden]>
> > >> Am 26.05.2011 11:22, schrieb Artyom Beilis:
> > >>
> > >> You can't use std::auto_ptr for pimpl implementation
> > >> in portable code. Doing so is undefined behavior. To
> > >> quote ISO/IEC 14882:2003 (§, p. 329):
> > >>
> > >> "In particular, the effects are undefined in the
> > >> following cases:
> > >> [...]
> > >> — if an incomplete type (3.9) is used as a template
> > >> argument when instantiating a template component,
> > >> unless specifically allowed for that component."
> > >>
> > >> which applies to most standard library types.
> > >
> > > When you actually implement Foo::~Foo() {} in cpp file
> > > the type of the data object is complete so the destructor
> > > is installed correctly.

Not relevant. Foo is an incomplete type and it is used as a template argument for std::auto_ptr in the header.

> > That's not correct. std::auto_ptr<data> is an
> > instantiation which uses an incomplete type as template
> > argument. Providing an non-inline destructor doesn't
> > magically make the data struct used in your example a
> > complete type.
> The quote you provide is too general about the library
> requirements.

No. It's right on point.

> Particularly, looking into auto_ptr. ( C++/2003
> standard)
> ~auto_ptr() throw();
> Requires: The expression delete get() is well formed.
> Effects: delete get().
> The expression delete get() is well formed when ~auto_ptr() is
> called in the destructor of Foo::~Foo() defined in cpp file.

That doesn't negate the point about the template argument.

> So it fills auto_ptr requirements.


> No problems I can see also I'm not aware of any compiler that
> does not handle this correctly (so far Intel, GCC, MSVC,
> SunStudio, HP's ACC, DECXX)

That doesn't mean the code is conforming. You can choose to rely on UB in your code, but Boost strives to do better.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at