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
* [Bug libstdc++/60497] 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 [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 ` redi at gcc dot gnu.org
2014-04-15 19:16 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-04-14 15:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Mon Apr 14 15:32:58 2014
New Revision: 209381
URL: http://gcc.gnu.org/viewcvs?rev=209381&root=gcc&view=rev
Log:
PR libstdc++/60497
* include/std/tuple (get): Qualify calls to prevent ADL.
* testsuite/20_util/tuple/60497.cc: New.
Added:
trunk/libstdc++-v3/testsuite/20_util/tuple/60497.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/std/tuple
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-04-15 19:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #1)
> Now the question would be: are there similar statements throughout the
> library that could benefit from the same treatment, or is this a special
> case?
It's a good question. I've fixed this case on the trunk, but we might want to
leave this open and backport it to the 4.8 and 4.9 branches, and look for other
cases.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-04-27 16:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Sun Apr 27 16:36:26 2014
New Revision: 209842
URL: http://gcc.gnu.org/viewcvs?rev=209842&root=gcc&view=rev
Log:
PR libstdc++/60497
* include/std/tuple (get): Qualify calls to prevent ADL.
* testsuite/20_util/tuple/60497.cc: New.
Added:
branches/gcc-4_8-branch/libstdc++-v3/testsuite/20_util/tuple/60497.cc
Modified:
branches/gcc-4_8-branch/libstdc++-v3/ChangeLog
branches/gcc-4_8-branch/libstdc++-v3/include/std/tuple
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (2 preceding siblings ...)
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
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-04-27 16:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |4.8.3
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 4.8.3, 4.9.1 and trunk.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (3 preceding siblings ...)
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
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-13 11:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Tue May 13 11:18:01 2014
New Revision: 210366
URL: http://gcc.gnu.org/viewcvs?rev=210366&root=gcc&view=rev
Log:
PR libstdc++/60497
* include/std/tuple (get, __tuple_compare): Qualify more calls to
prevent ADL. Cast comparison results to bool.
* testsuite/20_util/tuple/60497.cc: Test accessing rvalues.
* testsuite/20_util/tuple/comparison_operators/overloaded.cc: New.
Added:
trunk/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/overloaded.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/std/tuple
trunk/libstdc++-v3/testsuite/20_util/tuple/60497.cc
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (4 preceding siblings ...)
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
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-13 14:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |---
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This issue actually touches half the library.
Using std::bind with unique_ptr<B<A>> tries to complete A
Using unique_lock<Something<unique_ptr<B<A>>> tries to complete A
Using call_once(o, f, Something<unique_ptr<B<A>>) tries to complete A
etc. etc.
There are a few more unqualified std::get calls that I'm fixing, but most of
the problems come from using the built-in & operator, which does ADL and so
tries to complete A. That means we must use std::addressof even on internal
library types without an overloaded operator& if they have any template
arguments of user-defined types.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (5 preceding siblings ...)
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
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-13 16:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For example:
#include <memory>
#include <vector>
struct A;
template<typename T> struct B { T t; };
int main()
{
using UP = std::unique_ptr<B<A>>;
std::vector<UP*> v;
v = v;
}
The self-assignment test in std::vector uses &__rhs which does ADL and tries to
complete A.
Fixing this everywhere might take some time.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (6 preceding siblings ...)
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
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-13 17:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Tue May 13 17:22:08 2014
New Revision: 210388
URL: http://gcc.gnu.org/viewcvs?rev=210388&root=gcc&view=rev
Log:
PR libstdc++/60497
* include/debug/array (get): Qualify call to other get overload.
* include/profile/array (get): Likewise.
* include/std/array (get): Likewise.
* include/std/functional (_Mu, _Bind, _Bind_result): Qualify std::get.
* include/std/mutex (unique_lock, call_once): Use __addressof.
(__unlock_impl): Remove unused template.
(__try_to_lock): Declare inline.
(__try_lock_impl::__do_try_lock): Qualify function calls.
(lock): Avoid narrowing conversion.
* testsuite/20_util/bind/60497.cc: New.
* testsuite/23_containers/array/element_access/60497.cc: New.
* testsuite/30_threads/call_once/60497.cc: New.
* testsuite/30_threads/unique_lock/cons/60497.cc: New.
Added:
trunk/libstdc++-v3/testsuite/20_util/bind/60497.cc
trunk/libstdc++-v3/testsuite/23_containers/array/element_access/60497.cc
trunk/libstdc++-v3/testsuite/30_threads/call_once/60497.cc
trunk/libstdc++-v3/testsuite/30_threads/unique_lock/cons/60497.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/debug/array
trunk/libstdc++-v3/include/profile/array
trunk/libstdc++-v3/include/std/array
trunk/libstdc++-v3/include/std/functional
trunk/libstdc++-v3/include/std/mutex
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (7 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-06-22 14:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|4.8.3 |---
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (8 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-30 13:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #9)
> The self-assignment test in std::vector uses &__rhs which does ADL and tries
> to complete A.
Even if the &__rhs is changed to std::addressof(__rhs) it fails. Lookup for the
equality operator of std::allocator<UP*> also tries to complete A.
> Fixing this everywhere might take some time.
I think it's impossible.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/60497] 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 [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
` (9 preceding siblings ...)
2021-04-30 13:55 ` redi at gcc dot gnu.org
@ 2021-04-30 14:48 ` cvs-commit at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-30 14:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60497
--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:47915ef8477569b2fbd8001996aa4e542284bb24
commit r12-320-g47915ef8477569b2fbd8001996aa4e542284bb24
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Apr 30 14:45:42 2021 +0100
libstdc++: Use std::addressof to avoid ADL for operator& [PR 60497]
This is another small step towards avoiding the problems described in PR
60497, by using std::addressof to avoid ADL, so that we don't require
all template arguments to be complete.
libstdc++-v3/ChangeLog:
PR libstdc++/60497
* include/bits/basic_ios.tcc (basic_ios::copyfmt): use
std::addressof.
* include/bits/basic_string.tcc (basic_string::swap)
(basic_string::assign): Likewise.
* include/bits/deque.tcc (deque::operator=(const deque&)):
Likewise.
* include/bits/stl_tree.h (_Rb_tree::operator=(const * _Rb_tree&)):
Likewise.
* include/bits/vector.tcc (vector::operator=(const vector&)):
Likewise.
^ 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).