libstdc++: Allow unique_ptr<Incomplete[]>::operator[] [PR 101236]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 28 Jun 2021 11:59:19 +0000 (12:59 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 28 Jun 2021 13:20:55 +0000 (14:20 +0100)
commitb7a89c041aa1d67654f1ba7b2839e221c3e14748
treefe538e67277bcde4e2e2df8cc6d4f39b1151193c
parente5c422b7d8af6f42f8ab230133210742b7ac5661
libstdc++: Allow unique_ptr<Incomplete[]>::operator[] [PR 101236]

PR libstdc++/101236 shows that LLVM depends on being able to use
unique_ptr<T[]>::operator[] when T is incomplete. This is undefined, but
previously worked with libstdc++. When I added the conditional noexcept
to that operator we started to diagnose the incomplete type.

This change restores support for that case, by making the noexcept
condition check that the type is complete before checking whether
indexing on the pointer can throw.  A workaround for PR c++/101239 is
needed to avoid a bogus error where G++ fails to do SFINAE on the
ill-formed p[n] expression and gets an ICE. Instead of checking that the
p[n] expression is valid in the trailing-return-type, we only check that
the element_type is complete.

libstdc++-v3/ChangeLog:

PR libstdc++/101236
* include/bits/unique_ptr.h (unique_ptr<T[], D>::operator[]):
Fail gracefully if element_type is incomplete.
* testsuite/20_util/unique_ptr/cons/incomplete.cc: Clarify that
the standard doesn't require this test to work for array types.
* testsuite/20_util/unique_ptr/lwg2762.cc: Check that incomplete
types can be used with array specialization.
* testsuite/20_util/unique_ptr/101236.cc: New test.
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/unique_ptr/101236.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/unique_ptr/cons/incomplete.cc
libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc