public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60497] New: unique_ptr<T> tries to complete its type T even though it's not required to be a complete type
@ 2014-03-11  3:46 richard-gccbugzilla at metafoo dot co.uk
  2014-04-14 15:33 ` [Bug libstdc++/60497] " redi at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2014-03-11  3:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60497
           Summary: unique_ptr<T> tries to complete its type T even though
                    it's not required to be a complete type
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk

Consider:

  struct A;
  template<typename T> struct B { T t; };
  struct Deleter { void operator()(B<A>*) const; };
  std::unique_ptr<B<A>, Deleter> u;

It's not *entirely* clear to me that this is valid, but I think it is intended
to be. unique_ptr is required to support incomplete types like B<A>, but it's
not obvious that it can't *try* to complete the type. (If it does, this won't
compile, because B<A> has a field of incomplete type 'A'.)

g++ 4.8 rejects this:

<stdin>: In instantiation of 'struct B<A>':
tuple:758:35:   required from 'constexpr typename std::__add_ref<typename
std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type
std::get(std::tuple<_Elements ...>&) [with long unsigned int __i = 0ul;
_Elements = {B<A>*, Deleter}; typename std::__add_ref<typename
std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type = B<A>*&]'
bits/unique_ptr.h:182:32:   required from 'std::unique_ptr<_Tp,
_Dp>::~unique_ptr() [with _Tp = B<A>; _Dp = Deleter]'
<stdin>:5:34:   required from here
<stdin>:3:37: error: 'B<T>::t' has incomplete type
<stdin>:2:10: error: forward declaration of 'struct A'


This is ultimately a bug in std::tuple::get:

  template<std::size_t __i, typename... _Elements>
    constexpr typename __add_ref<
                      typename tuple_element<__i, tuple<_Elements...>>::type
                    >::type
    get(tuple<_Elements...>& __t) noexcept
    { return __get_helper<__i>(__t); }

Note that this performs ADL to find __get_helper, which requires the associated
classes of __t to be complete, and those include B<A>. So this reduces to:

  struct A;
  template<typename T> struct B { T t; };
  std::tuple<B<A>*> t(nullptr);
  auto *p = std::get<0>(t);

... which is rejected in the same way.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-04-30 14:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-11  3:46 [Bug c++/60497] New: unique_ptr<T> tries to complete its type T even though it's not required to be a complete type richard-gccbugzilla at metafoo dot co.uk
2014-04-14 15:33 ` [Bug libstdc++/60497] " redi at gcc dot gnu.org
2014-04-15 19:16 ` redi at gcc dot gnu.org
2014-04-27 16:37 ` redi at gcc dot gnu.org
2014-04-27 16:38 ` redi at gcc dot gnu.org
2014-05-13 11:18 ` redi at gcc dot gnu.org
2014-05-13 14:30 ` redi at gcc dot gnu.org
2014-05-13 16:50 ` redi at gcc dot gnu.org
2014-05-13 17:22 ` redi at gcc dot gnu.org
2015-06-22 14:26 ` rguenth at gcc dot gnu.org
2021-04-30 13:55 ` redi at gcc dot gnu.org
2021-04-30 14:48 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).