public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "richard-gccbugzilla at metafoo dot co.uk" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/60497] New: unique_ptr<T> tries to complete its type T even though it's not required to be a complete type
Date: Tue, 11 Mar 2014 03:46:00 -0000	[thread overview]
Message-ID: <bug-60497-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2014-03-11  3:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-11  3:46 richard-gccbugzilla at metafoo dot co.uk [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-60497-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).