From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 5F0EE3842434 for ; Tue, 22 Sep 2020 07:43:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5F0EE3842434 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-422-1pZ5jlWWP76JN1xWN8Of9A-1; Tue, 22 Sep 2020 03:43:37 -0400 X-MC-Unique: 1pZ5jlWWP76JN1xWN8Of9A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 676081074655; Tue, 22 Sep 2020 07:43:36 +0000 (UTC) Received: from localhost (unknown [10.33.36.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14C425C1D0; Tue, 22 Sep 2020 07:43:35 +0000 (UTC) Date: Tue, 22 Sep 2020 08:43:35 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [committed] libstdc++: Use correct argument type for __use_alloc [PR 96803] Message-ID: <20200922074335.GQ6061@redhat.com> References: <20200826183429.GA953143@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200826183429.GA953143@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="cEobB2knsyc5ebfU" Content-Disposition: inline X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Sep 2020 07:43:41 -0000 --cEobB2knsyc5ebfU Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 26/08/20 19:34 +0100, Jonathan Wakely wrote: >The _Tuple_impl constructor for allocator-extended construction from a >different tuple type uses the _Tuple_impl's own _Head type in the >__use_alloc test. That is incorrect, because the argument tuple could >have a different type. Using the wrong type might select the >leading-allocator convention when it should use the trailing-allocator >convention, or vice versa. > >libstdc++-v3/ChangeLog: > > PR libstdc++/96803 > * include/std/tuple > (_Tuple_impl(allocator_arg_t, Alloc, const _Tuple_impl&)): > Replace parameter pack with a type parameter and a pack and pass > the first type to __use_alloc. > * testsuite/20_util/tuple/cons/96803.cc: New test. While backporting 5494edae83ad33c769bd1ebc98f0c492453a6417 I noticed that it's still not correct. I made the allocator-extended constructor use the right type for the uses-allocator construction detection, but I used an rvalue when it should be a const lvalue. This should fix it properly this time. libstdc++-v3/ChangeLog: PR libstdc++/96803 * include/std/tuple (_Tuple_impl(allocator_arg_t, Alloc, const _Tuple_impl&)): Use correct value category in __use_alloc call. * testsuite/20_util/tuple/cons/96803.cc: Check with constructors that require correct value category to be used. Tested powerpc64le-linux. Committed to trunk. --cEobB2knsyc5ebfU Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 7825399092d572ce8ea82c4aa8dfeb65076b0e52 Author: Jonathan Wakely Date: Tue Sep 22 08:42:18 2020 libstdc++: Use correct argument type for __use_alloc, again [PR 96803] While backporting 5494edae83ad33c769bd1ebc98f0c492453a6417 I noticed that it's still not correct. I made the allocator-extended constructor use the right type for the uses-allocator construction detection, but I used an rvalue when it should be a const lvalue. This should fix it properly this time. libstdc++-v3/ChangeLog: PR libstdc++/96803 * include/std/tuple (_Tuple_impl(allocator_arg_t, Alloc, const _Tuple_impl&)): Use correct value category in __use_alloc call. * testsuite/20_util/tuple/cons/96803.cc: Check with constructors that require correct value category to be used. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 06f56337ce4..11ad1991108 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -355,7 +355,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const _Tuple_impl<_Idx, _UHead, _UTails...>& __in) : _Inherited(__tag, __a, _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)), - _Base(__use_alloc<_Head, _Alloc, _UHead>(__a), + _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a), _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)) { } diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/96803.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/96803.cc index 9d3c07d55b2..867a42150e0 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/cons/96803.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/96803.cc @@ -38,4 +38,25 @@ test01() // std::tuple chooses wrong constructor for uses-allocator construction std::tuple o; std::tuple nok(std::allocator_arg, std::allocator(), o); + + std::tuple oo; + std::tuple nn(std::allocator_arg, std::allocator(), oo); +} + +struct Y +{ + using allocator_type = std::allocator; + + Y(const X&) { } + Y(const X&, const allocator_type&) { } + + Y(X&&) { } + Y(std::allocator_arg_t, const allocator_type&, X&&) { } +}; + +void +test02() +{ + std::tuple o{1, 1}; + std::tuple oo(std::allocator_arg, std::allocator(), o); } --cEobB2knsyc5ebfU--