From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 6B938398797F for ; Fri, 30 Oct 2020 21:34:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6B938398797F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-rcrN07pVPaqFWPlsTEcyzg-1; Fri, 30 Oct 2020 17:34:35 -0400 X-MC-Unique: rcrN07pVPaqFWPlsTEcyzg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C902C802ED5; Fri, 30 Oct 2020 21:34:32 +0000 (UTC) Received: from localhost (unknown [10.33.36.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4633D5B4D0; Fri, 30 Oct 2020 21:34:32 +0000 (UTC) Date: Fri, 30 Oct 2020 21:34:31 +0000 From: Jonathan Wakely To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Don't initialize from *this inside some views [PR97600] Message-ID: <20201030213431.GL503596@redhat.com> References: <20201030151148.2588076-1-ppalka@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201030151148.2588076-1-ppalka@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Oct 2020 21:34:39 -0000 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. > >This is problematic because the constraint range requires the >begin()/end() member to be callable. But it's not callable until we've >deduced its return type, so evaluation of range yields false >at this point. And if at any point after both members are instantiated >(and their return types deduced) we evaluate range 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::operator bool(). And this conversion >function's constraints indirectly require range. > >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 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.