public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Don't initialize from *this inside some views [PR97600]
Date: Fri, 30 Oct 2020 21:34:31 +0000	[thread overview]
Message-ID: <20201030213431.GL503596@redhat.com> (raw)
In-Reply-To: <20201030151148.2588076-1-ppalka@redhat.com>

On 30/10/20 11:11 -0400, Patrick Palka via Libstdc++ wrote:
>This works around a subtle issue where instantiating the begin()/end()
>member of some views (as part of return type deduction) inadvertently
>requires computing the satisfaction value of range<foo_view>.
>
>This is problematic because the constraint range<foo_view> requires the
>begin()/end() member to be callable.  But it's not callable until we've
>deduced its return type, so evaluation of range<foo_view> yields false
>at this point.  And if at any point after both members are instantiated
>(and their return types deduced) we evaluate range<foo_view> again, this
>time it will yield true since the begin()/end() members are now both
>callable.  This makes the program ill-formed according to
>[temp.constr.atomic]/3:
>
>  If, at different points in the program, the satisfaction result is
>  different for identical atomic constraints and template arguments, the
>  program is ill-formed, no diagnostic required.
>
>The views affected by this issue are those whose begin()/end() member
>has a placeholder return type and that member initializes an _Iterator
>or _Sentinel object from a reference to *this.  The second condition is
>relevant because it means explicit conversion functions are considered
>during overload resolution (as per [over.match.copy], I think), and
>therefore it causes g++ to check the constraints of the conversion
>function view_interface<foo_view>::operator bool().  And this conversion
>function's constraints indirectly require range<foo_view>.
>
>This issue is observable on trunk only with basic_istream_view (as in
>the testcase in the PR).  But a pending patch that makes g++ memoize
>constraint satisaction values indefinitely (it currently invalidates
>the satisfaction cache on various events) causes many existing tests for
>the other affected views to fail, because range<foo_view> then remains
>false for the whole compilation.
>
>This patch works around this issue by adjusting the constructors of the
>_Iterator and _Sentinel types of the affected views to take their
>foo_view argument by pointer instead of by reference, so that g++ no
>longer considers explicit conversion functions when resolving the
>direct-initialization inside these views' begin()/end() members.

Nice solution.

>Tested on x86_64-pc-linux-gnu, and also verified that this fixes the
>testsuite failures when combined with the mentioned frontend patch
>(https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557237.html).
>Does this look OK for trunk?

Yes, thanks.



      reply	other threads:[~2020-10-30 21:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30 15:11 Patrick Palka
2020-10-30 21:34 ` 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=20201030213431.GL503596@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.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).