This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: unique_ptr's new static_assert check whether deleter can be invoked fails


On Mon, 17 Sep 2018 at 17:41, Stephan Bergmann <sbergman@redhat.com> wrote:
>
> Compiling LibreOffice with recent GCC trunk, I came across an error like
> with this reproducer
>
> > $ cat test14.cc
> > #include <memory>
> > struct S1;
> > struct S2;
> > struct D { void operator ()(S1 *); };
> > class C {
> >     std::unique_ptr<S2, D> m;
> >     C();
> >     C(C const &);
> >     ~C();
> >     C & operator =(C const &);
> > };
> >
> > $ gcc/inst/bin/g++ -c test14.cc
> > In file included from /home/sbergman/gcc/inst/include/c++/9.0.0/memory:80,
> >                  from test14.cc:1:
> > /home/sbergman/gcc/inst/include/c++/9.0.0/bits/unique_ptr.h: In instantiation of ‘class std::__uniq_ptr_impl<S2, D>’:
> > /home/sbergman/gcc/inst/include/c++/9.0.0/bits/unique_ptr.h:172:33:   required from ‘class std::unique_ptr<S2, D>’
> > test14.cc:6:28:   required from here
> > /home/sbergman/gcc/inst/include/c++/9.0.0/bits/unique_ptr.h:145:22: error: static assertion failed: unique_ptr's deleter must be invocable with a pointer
> > 145 |       static_assert( __is_invocable<_Dp&, pointer&>::value,
> >     |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> where S2 is an incomplete type, so the static_assert in unique_ptr
> (added recently with
> <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=199f729ee3a6bd564151cda4caac289fbe7105cc>
> "Implement LWG 2905 changes to constrain unique_ptr constructors") can't
> determine that D can be invoked with an S2* (which it can if S2 is
> derived from S1).
>
> I'm not sure whether this is a bug in LibreOffice (which would need to
> make sure S2 is a complete type when defining C), or a too aggressive
> static_assert in libstdc++?

The static_assert looks too aggressive to me. It should be possible to
use a unique_ptr<incomplete_type> as a member regardless
of what the deleter does.


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