From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id E0758386F44A for ; Thu, 7 May 2020 20:44:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E0758386F44A 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-430-ajY5j-WqMBObOssyE2482g-1; Thu, 07 May 2020 16:44:48 -0400 X-MC-Unique: ajY5j-WqMBObOssyE2482g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2ADF5460; Thu, 7 May 2020 20:44:47 +0000 (UTC) Received: from localhost (unknown [10.33.36.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 801215D9C5; Thu, 7 May 2020 20:44:46 +0000 (UTC) Date: Thu, 7 May 2020 21:44:45 +0100 From: Jonathan Wakely To: Martin Liska Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH 4/4] Use const for template argument. Message-ID: <20200507204445.GG2678@redhat.com> References: <20200506100127.GY2678@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200506100127.GY2678@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="xkXJwpr35CY/Lc3I" Content-Disposition: inline X-Spam-Status: No, score=-19.7 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: 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: Thu, 07 May 2020 20:44:52 -0000 --xkXJwpr35CY/Lc3I Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 06/05/20 11:01 +0100, Jonathan Wakely wrote: >On 04/02/20 14:55 +0100, Martin Liska wrote: >>diff --git a/libstdc++-v3/include/parallel/multiway_merge.h b/libstdc++-v= 3/include/parallel/multiway_merge.h >>index 983c7b2bd9a..97a9ce0feb7 100644 >>--- a/libstdc++-v3/include/parallel/multiway_merge.h >>+++ b/libstdc++-v3/include/parallel/multiway_merge.h >>@@ -118,7 +118,7 @@ namespace __gnu_parallel >> * @return @c true if less. */ >> friend bool >> operator<(_GuardedIterator<_RAIter, _Compare>& __bi1, >>- _GuardedIterator<_RAIter, _Compare>& __bi2) >>+ _GuardedIterator<_RAIter, const _Compare>& __bi2) >> { >> if (__bi1._M_current =3D=3D __bi1._M_end) // __bi1 is sup >> return __bi2._M_current =3D=3D __bi2._M_end; // __bi2 is not su= p >>@@ -188,7 +188,7 @@ namespace __gnu_parallel >> * @return @c true if less. */ >> friend bool >> operator<(_UnguardedIterator<_RAIter, _Compare>& __bi1, >>- _UnguardedIterator<_RAIter, _Compare>& __bi2) >>+ _UnguardedIterator<_RAIter, const _Compare>& __bi2) >> { >> // Normal compare. >> return (__bi1.__comp)(*__bi1, *__bi2); > > >This is completely bogus, please revert. > >The cppcheck warning is saying that it could be: > > const _UnguardedIterator<_RAIter, _Compare>& > >which is completely different from: > > _UnguardedIterator<_RAIter, const _Compare>& > >Also both parameters of operator< should have been changed, not just >one, and operator<=3D should have the same change. > >But cppcheck is completely wrong anyway. The operator* member of >_GuardedIterator and _UnguardedIterator is not const, so trying to >dereference *__b1 and *__b2 would fail. > >Nack nack nack. Here's a correct fix for the cppcheck complaint. Tested powerpc64le-linux, 'make check check-parallel', committed to master. --xkXJwpr35CY/Lc3I Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-Transfer-Encoding: quoted-printable commit 4cbc9d8b346b932f34828a51e8822881413951b7 Author: Jonathan Wakely Date: Thu May 7 21:43:49 2020 +0100 libstdc++: Make relational operators work with const guarded iterators = (PR 92472) =20 This is a correct fix for the incorrect cppcheck suggestion to make these parameters const. In order to that, the dereference operators nee= d to be const. The conversions to the underlying iterator can be const too. =20 PR c/92472 * include/parallel/multiway_merge.h (_GuardedIterator::operator= *) (_GuardedIterator::operator _RAIter, _UnguardedIterator::operat= or*) (_UnguardedIterator::operator _RAIter): Add const qualifier. (operator<(_GuardedIterator&, _GuardedIterator&) (operator<=3D(_GuardedIterator&, _GuardedIterator&) (operator<(_UnguardedIterator&, _UnguardedIterator&) (operator<=3D(_UnguardedIterator&, _UnguardedIterator&): Change parameters to const references. diff --git a/libstdc++-v3/include/parallel/multiway_merge.h b/libstdc++-v3/= include/parallel/multiway_merge.h index 983c7b2bd9a..52a8b2ca9e7 100644 --- a/libstdc++-v3/include/parallel/multiway_merge.h +++ b/libstdc++-v3/include/parallel/multiway_merge.h @@ -104,12 +104,12 @@ namespace __gnu_parallel /** @brief Dereference operator. * @return Referenced element. */ typename std::iterator_traits<_RAIter>::value_type& - operator*() + operator*() const { return *_M_current; } =20 /** @brief Convert to wrapped iterator. * @return Wrapped iterator. */ - operator _RAIter() + operator _RAIter() const { return _M_current; } =20 /** @brief Compare two elements referenced by guarded iterators. @@ -117,8 +117,8 @@ namespace __gnu_parallel * @param __bi2 Second iterator. * @return @c true if less. */ friend bool - operator<(_GuardedIterator<_RAIter, _Compare>& __bi1, -=09=09_GuardedIterator<_RAIter, _Compare>& __bi2) + operator<(const _GuardedIterator<_RAIter, _Compare>& __bi1, +=09=09const _GuardedIterator<_RAIter, _Compare>& __bi2) { =09if (__bi1._M_current =3D=3D __bi1._M_end) // __bi1 is sup =09 return __bi2._M_current =3D=3D __bi2._M_end; // __bi2 is not sup @@ -132,8 +132,8 @@ namespace __gnu_parallel * @param __bi2 Second iterator. * @return @c True if less equal. */ friend bool - operator<=3D(_GuardedIterator<_RAIter, _Compare>& __bi1, -=09=09 _GuardedIterator<_RAIter, _Compare>& __bi2) + operator<=3D(const _GuardedIterator<_RAIter, _Compare>& __bi1, +=09=09 const _GuardedIterator<_RAIter, _Compare>& __bi2) { =09if (__bi2._M_current =3D=3D __bi2._M_end) // __bi1 is sup =09 return __bi1._M_current !=3D __bi1._M_end; // __bi2 is not sup @@ -174,12 +174,12 @@ namespace __gnu_parallel /** @brief Dereference operator. * @return Referenced element. */ typename std::iterator_traits<_RAIter>::value_type& - operator*() + operator*() const { return *_M_current; } =20 /** @brief Convert to wrapped iterator. * @return Wrapped iterator. */ - operator _RAIter() + operator _RAIter() const { return _M_current; } =20 /** @brief Compare two elements referenced by unguarded iterators. @@ -187,8 +187,8 @@ namespace __gnu_parallel * @param __bi2 Second iterator. * @return @c true if less. */ friend bool - operator<(_UnguardedIterator<_RAIter, _Compare>& __bi1, -=09=09_UnguardedIterator<_RAIter, _Compare>& __bi2) + operator<(const _UnguardedIterator<_RAIter, _Compare>& __bi1, +=09=09const _UnguardedIterator<_RAIter, _Compare>& __bi2) { =09// Normal compare. =09return (__bi1.__comp)(*__bi1, *__bi2); @@ -199,8 +199,8 @@ namespace __gnu_parallel * @param __bi2 Second iterator. * @return @c True if less equal. */ friend bool - operator<=3D(_UnguardedIterator<_RAIter, _Compare>& __bi1, -=09=09 _UnguardedIterator<_RAIter, _Compare>& __bi2) + operator<=3D(const _UnguardedIterator<_RAIter, _Compare>& __bi1, +=09=09 const _UnguardedIterator<_RAIter, _Compare>& __bi2) { =09// Normal compare. =09return !(__bi1.__comp)(*__bi2, *__bi1); --xkXJwpr35CY/Lc3I--