public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Tim Song <t.canens.cpp@gmail.com>
Cc: Patrick Palka <ppalka@redhat.com>,
	"libstdc++" <libstdc++@gcc.gnu.org>,
	 gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [committed] libstdc++: Implement LWG 2762 for std::unique_ptr::operator*
Date: Mon, 28 Jun 2021 15:19:09 +0100	[thread overview]
Message-ID: <CACb0b4=VC7nxq3ZQvfgpzA32Eaf8ZALSy7azEsgZtAVkS8vLUQ@mail.gmail.com> (raw)
In-Reply-To: <CAPQZVxtph_YLrgC-RcztKss4dh8QjzmySPyj-5U4PPsT55yjcg@mail.gmail.com>

On Thu, 24 Jun 2021 at 22:11, Tim Song wrote:
>
> That example violates http://eel.is/c++draft/unique.ptr.runtime.general#3

Even though it's undefined I committed a workaround to allow it,
because it breaks LLVM:
https://gcc.gnu.org/pipermail/libstdc++/2021-June/052851.html
(I forgot to send that mail as a reply to this thread, sorry).

> On Thu, Jun 24, 2021 at 1:55 PM Patrick Palka via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > On Thu, 24 Jun 2021, Jonathan Wakely via Libstdc++ wrote:
> >
> > > The LWG issue proposes to add a conditional noexcept-specifier to
> > > std::unique_ptr's dereference operator. The issue is currently in
> > > Tentatively Ready status, but even if it isn't voted into the draft, we
> > > can do it as a conforming extensions. This commit also adds a similar
> > > noexcept-specifier to operator[] for the unique_ptr<T[], D> partial
> > > specialization.
> >
> > The conditional noexcept added to unique_ptr<T[]>::operator[] seems to break
> > the case where T is complete only after the fact:
> >
> >   struct T;
> >   extern std::unique_ptr<T[]> p;
> >   auto& t = p[1];
> >   struct T { };
> >
> > /include/c++/12.0.0/bits/unique_ptr.h: In instantiation of ‘typename std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp [], _Dp>::operator[](std::size_t) co
> > nst [with _Tp = A; _Dp = std::default_delete<A []>; typename std::add_lvalue_reference<_Tp>::type = A&; std::size_t = long unsigned int]’:
> > testcase.cc:5:14:   required from here
> > /include/c++/12.0.0/bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘struct A’
> >   658 |       noexcept(noexcept(std::declval<pointer>()[std::declval<size_t&>()]))
> >       |                         ~~~~~~~~~~~~~~~~~~~~~~~^
> > testcase.cc:3:8: note: forward declaration of ‘struct A’
> >     3 | struct A;
> >       |        ^
> >
> > >
> > > Also ensure that all dereference operators for shared_ptr are noexcept,
> > > and adds tests for the std::optional accessors modified by the issue,
> > > which were already noexcept in our implementation.
> > >
> > > Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
> > >
> > > libstdc++-v3/ChangeLog:
> > >
> > >       * include/bits/shared_ptr_base.h (__shared_ptr_access::operator[]):
> > >       Add noexcept.
> > >       * include/bits/unique_ptr.h (unique_ptr::operator*): Add
> > >       conditional noexcept as per LWG 2762.
> > >       * testsuite/20_util/shared_ptr/observers/array.cc: Check that
> > >       dereferencing cannot throw.
> > >       * testsuite/20_util/shared_ptr/observers/get.cc: Likewise.
> > >       * testsuite/20_util/optional/observers/lwg2762.cc: New test.
> > >       * testsuite/20_util/unique_ptr/lwg2762.cc: New test.
> > >
> > > Tested powerpc64le-linux. Committed to trunk.
> > >
> > >
>


      reply	other threads:[~2021-06-28 14:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24 13:10 Jonathan Wakely
2021-06-24 18:53 ` Patrick Palka
2021-06-24 19:29   ` Jonathan Wakely
2021-06-24 21:10   ` Tim Song
2021-06-28 14:19     ` Jonathan Wakely [this message]

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='CACb0b4=VC7nxq3ZQvfgpzA32Eaf8ZALSy7azEsgZtAVkS8vLUQ@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    --cc=t.canens.cpp@gmail.com \
    /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).