[cfe-dev] problem with std::function and virtual destructor

Rich E reakinator at gmail.com
Sun Jul 15 13:55:41 PDT 2012


Thank you for the explanations..

On Sun, Jul 15, 2012 at 1:38 PM, Steve Ramsey <clang at lucena.com> wrote:

> On Jul 15, 2012, at 12:59 AM, Richard Smith wrote:
> >
> > I'm not sure why instantiating std::function<void(X&)>::operator= would
> require X to be complete -- libstdc++ does not behave that way. It's
> possible this is a bug in libc++, but it's also possible that the standard
> allows this behavior and libstdc++ is just more permissive. Hopefully
> Howard can help with that part.
>
> This is correct behavior as per FDIS 12.8.18. Specifically, since there's
> a user-declared copy constructor, there needs to be a user-declared
> copy-assignment operator, if you want one; otherwise, the implicitly
> declared one is defined as deleted.


Excuse my ignorance, but how is there a user-declared copy constructor?



> Consider:
>
> //////////
> #include <functional>
>
> struct X{
>     typedef std::function<void(X&)> callback_type;
>     virtual ~X() {}
> //    X & operator = (const X &) = default;
> private:
>     callback_type _cb;
> };
>
> int main(){}
> /////////
>
> Uncommenting the copy-assignment operator function declaration makes the
> error go away. Note that in this case, the copy constructor is deleted, and
> the default constructor, move constructor, and move-assignment operator are
> suppressed.
>

Sorry again, I don't understand why you must declare the copy assignment
operator as default, else it will be deleted or suppressed (you mean not
generated by compiler?).  Could you please explain?

Thanks again,
Rich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120715/c8c7c280/attachment.html>


More information about the cfe-dev mailing list