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.