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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3FD0F385842F for ; Fri, 1 Oct 2021 14:05:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3FD0F385842F 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-253-zfGM81r3Nl6jQN4Yt94N7w-1; Fri, 01 Oct 2021 10:04:59 -0400 X-MC-Unique: zfGM81r3Nl6jQN4Yt94N7w-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 8D77F652; Fri, 1 Oct 2021 14:04:58 +0000 (UTC) Received: from localhost (unknown [10.33.36.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38DF45DA61; Fri, 1 Oct 2021 14:04:58 +0000 (UTC) Date: Fri, 1 Oct 2021 15:04:57 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix _ForwardIteratorConcept for __gnu_debug::vector Message-ID: MIME-Version: 1.0 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="ax4lglxQzfD9fGNu" Content-Disposition: inline X-Spam-Status: No, score=-13.8 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_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 01 Oct 2021 14:05:04 -0000 --ax4lglxQzfD9fGNu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The recent changes to the _GLIBCXX_CONCEPT_CHECKS checks for forward iterators don't work for vector iterators in debug mode, because the _Safe_iterator specializations don't match the special cases I added for _Bit_iterator and _Bit_const_iterator. This refactors the _ForwardIteratorReferenceConcept class template to identify vector iterators using a new trait, which also works for debug iterators. libstdc++-v3/ChangeLog: * include/bits/boost_concept_check.h (_Is_vector_bool_iterator): New trait to identify vector iterators, including debug ones. (_ForwardIteratorReferenceConcept): Add default template argument using _Is_vector_bool_iterator and use it in partial specialization for the vector cases. (_Mutable_ForwardIteratorReferenceConcept): Likewise. * testsuite/24_iterators/operations/prev_neg.cc: Adjust dg-error line number. Tested x86_64-linux. Committed to trunk. --ax4lglxQzfD9fGNu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit c67339d12653c33f85f8141789d7a7cf38831cbd Author: Jonathan Wakely Date: Thu Sep 30 11:25:15 2021 libstdc++: Fix _ForwardIteratorConcept for __gnu_debug::vector The recent changes to the _GLIBCXX_CONCEPT_CHECKS checks for forward iterators don't work for vector iterators in debug mode, because the _Safe_iterator specializations don't match the special cases I added for _Bit_iterator and _Bit_const_iterator. This refactors the _ForwardIteratorReferenceConcept class template to identify vector iterators using a new trait, which also works for debug iterators. libstdc++-v3/ChangeLog: * include/bits/boost_concept_check.h (_Is_vector_bool_iterator): New trait to identify vector iterators, including debug ones. (_ForwardIteratorReferenceConcept): Add default template argument using _Is_vector_bool_iterator and use it in partial specialization for the vector cases. (_Mutable_ForwardIteratorReferenceConcept): Likewise. * testsuite/24_iterators/operations/prev_neg.cc: Adjust dg-error line number. diff --git a/libstdc++-v3/include/bits/boost_concept_check.h b/libstdc++-v3/include/bits/boost_concept_check.h index 71c99c13e93..81352518c50 100644 --- a/libstdc++-v3/include/bits/boost_concept_check.h +++ b/libstdc++-v3/include/bits/boost_concept_check.h @@ -47,11 +47,19 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_BEGIN_NAMESPACE_CONTAINER struct _Bit_iterator; struct _Bit_const_iterator; +_GLIBCXX_END_NAMESPACE_CONTAINER _GLIBCXX_END_NAMESPACE_VERSION } +namespace __gnu_debug +{ + template + class _Safe_iterator; +} + namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -478,10 +486,32 @@ struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; }; _ValueT __val() const; }; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-variable" + template + struct _Is_vector_bool_iterator + { static const bool __value = false; }; - template +#ifdef _GLIBCXX_DEBUG + namespace __cont = ::std::_GLIBCXX_STD_C; +#else + namespace __cont = ::std; +#endif + + // Trait to identify vector::iterator + template <> + struct _Is_vector_bool_iterator<__cont::_Bit_iterator> + { static const bool __value = true; }; + + // And for vector::const_iterator. + template <> + struct _Is_vector_bool_iterator<__cont::_Bit_const_iterator> + { static const bool __value = true; }; + + // And for __gnu_debug::vector iterators too. + template + struct _Is_vector_bool_iterator<__gnu_debug::_Safe_iterator<_It, _Seq, _Tag> > + : _Is_vector_bool_iterator<_It> { }; + + template ::__value> struct _ForwardIteratorReferenceConcept { void __constraints() { @@ -493,7 +523,7 @@ struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; }; } }; - template + template ::__value> struct _Mutable_ForwardIteratorReferenceConcept { void __constraints() { @@ -503,26 +533,22 @@ struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; }; } }; - // vector::iterator is not a real forward reference, but pretend it is. - template <> - struct _ForwardIteratorReferenceConcept + // vector iterators are not real forward iterators, but we ignore that. + template + struct _ForwardIteratorReferenceConcept<_Tp, true> { void __constraints() { } }; - // vector::iterator is not a real forward reference, but pretend it is. - template <> - struct _Mutable_ForwardIteratorReferenceConcept + // vector iterators are not real forward iterators, but we ignore that. + template + struct _Mutable_ForwardIteratorReferenceConcept<_Tp, true> { void __constraints() { } }; - // And vector::const iterator too. - template <> - struct _ForwardIteratorReferenceConcept - { - void __constraints() { } - }; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" template struct _ForwardIteratorConcept diff --git a/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc b/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc index d22491999a8..cc648549a06 100644 --- a/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc +++ b/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc @@ -38,5 +38,5 @@ test02() { const Y array[1] = { }; (void) std::prev(array + 1); - // { dg-error "forward_iterator" "" { target *-*-* } 231 } + // { dg-error "forward_iterator" "" { target *-*-* } 239 } } --ax4lglxQzfD9fGNu--