From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 0374A38618BC; Mon, 19 Feb 2024 08:12:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0374A38618BC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0374A38618BC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708330370; cv=none; b=nD+mtf0fmIANjQskJk4CgDyZVpawrkP/8SbCAAQYDhScBTwijwl/Y55wB0KQgt1myeEEk/RXSq3OTzU06XVxS1fD6oacNsGhYVYh+LE1RroXkCgV/N+D3j7cj6qIshyeJ7+ds4L0B1vOx0/ZyqXRTwA5Rcg/J26YlCs8FTksE8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708330370; c=relaxed/simple; bh=TcuLT2+Jgyqhs/s1bXscp8WooY3cADFnFrpU6t03uLg=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=CGEIV+DdIpU4Mgi4DdgpfduS+kpusniJUed9F/FI6TnhT6y3gHDTyzY/0HqX3tJZU802nuUzBK2pwpy8JCOD2f9n0Iu0VBIHVrBqtvgR7VQfnbS1lC1PzLn0Oo7iuIDxDQiWnvRBAmx665q0HWcNNSFb+/b6FrFRiYNFE5tedGk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-563d56ee65cso3196290a12.2; Mon, 19 Feb 2024 00:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708330364; x=1708935164; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=oY91XO9vHYqXJnD6tzYz+EjN4p5DkCqXWucenUseal0=; b=PKD7Nypja5HDDBijYnpoV4+uY6FS7SiqzA9YAfUUCD7J6TL/GCiGAasAkJ1LKc3SDD XveSecNtljkTVs6PCE0C1ED2IuHVP62YUlltnS96+5OUutf0AxzMQufuVXTliGhXTkYT 78cZg1P0Zv3/0U9EJtluqXVPyEA7nAAL6P3IjGE7C5qzLsIahPFyBouqaTPJ75yhV8sz VmjqyEem5zCsp9S41yHVlEQuMtn6r6Noqi9wK5hZsVaid8+Y0N1X8K+Lr+c+7EF2M+UU VFNC5MpG9zMzbnvU1nlwm7RYzoj17Mq8I/P4EZOYq9yIlt3eEg4b2XO3WS6SvBfPQ+nB JLMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708330364; x=1708935164; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oY91XO9vHYqXJnD6tzYz+EjN4p5DkCqXWucenUseal0=; b=CBOU5ESjENKyawRBa6DVfrqlQEju7E4Ie+dGlqwI8pkl+iK0QTGTYJvjtPYB4lK38N 8ZcR281Z7mHfsHdGWeGdQRUMSHGk9jI/+4+NdAY02HDZUjXZayrBPG1I/6EeFbY9ea2k KIuXjfZQ5HynoUO/Pz+qQjqZZ2PFgORFLyr671iMk2T4sOI8zPLANNMsCbG05cM8k/3l 27H7U6uf7xG/8Yhz77gRKeqyG66hH9En3qE3sEqFKjQxejkiRl2/e8VSkfLRcdB6MEPE /Gpasp41x4fnK6ZLcugP5qoRuVzdyiz8mJI5yF3zxTUmgopxCowYXQtRYfojqz9mHH5F /oIQ== X-Forwarded-Encrypted: i=1; AJvYcCU70R1szmHMJFHOf8Z14dw3tQIXcCPuuN5BxZfMqnIUSCXyQo9RKmXNPEFNh1COP64oLEYadN4M/gq1STnZz8aIE7eGHOeDkg== X-Gm-Message-State: AOJu0YwgFmce2Nm/PhCtYvwT7KdH1pp/TKqFALmRxNZTcJ+ul5/59AdI MRAPKhr2kIhioUZk5BYltN8JPGdCaE657vRvV6ccVANlL8c5WOwLgieT3RJgtx6Pm9ISF+CTJUy K6GKfO9WaDbhYJc/epwXFCj7I5lU= X-Google-Smtp-Source: AGHT+IHyA9vkgIYfn5dGEH/azT1xGFB4Ih+9E/692zVhw2se6NSxhFshTRJL/66DyEK2ziFtQHWJbKljODeqFjf9XPw= X-Received: by 2002:a17:906:3bc7:b0:a3c:8d9a:40cc with SMTP id v7-20020a1709063bc700b00a3c8d9a40ccmr7951013ejf.7.1708330364352; Mon, 19 Feb 2024 00:12:44 -0800 (PST) MIME-Version: 1.0 References: <4c78d538-da4d-4a54-987d-3c4257913035@gmail.com> <9a6615ee-0a2c-4bcb-ad13-ba810edb9ee1@gmail.com> <3e1e1652-4320-4b63-a72f-572f045780ca@gmail.com> In-Reply-To: From: Jonathan Wakely Date: Mon, 19 Feb 2024 08:12:31 +0000 Message-ID: Subject: Re: [PATCH][_GLIBCXX_DEBUG] Fix std::__niter_base behavior To: Stephan Bergmann Cc: "libstdc++" , gcc-patches , =?UTF-8?Q?Fran=C3=A7ois_Dumont?= , Jonathan Wakely Content-Type: multipart/alternative; boundary="00000000000086bcb20611b7a82d" X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --00000000000086bcb20611b7a82d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 19 Feb 2024, 07:08 Stephan Bergmann, wrote: > On 2/17/24 15:14, Fran=C3=A7ois Dumont wrote: > > Thanks for the link, tested and committed. > > I assume this is the cause for the below failure now, > Yes, the new >=3D C++11 overload of __niter_base recursively unwraps multip= le layers of wrapping, so that a safe iterator wrapping a normal iterator wrapping a pointer is unwrapped to just a pointer. But then __niter_wrap doesn't restore both layers. I think the change might need to be reverted. > > $ cat test.cc > > #include > > #include > > void f(std::vector &v, void const * p) { > > std::erase(v, p); > > } > > > $ ~/gcc/inst/bin/g++ -std=3Dc++20 -D_GLIBCXX_DEBUG -fsyntax-only test.cc > > In file included from ~/gcc/inst/include/c++/14.0.1/algorithm:60, > > from test.cc:1: > > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h: In instantiation of > =E2=80=98constexpr _From std::__niter_wrap(_From, _To) [with _From =3D > __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator __cxx1998::vector > >, > __debug::vector, random_access_iterator_tag>; _To =3D > __gnu_cxx::__normal_iterator allocator > >]=E2=80=99: > > ~/gcc/inst/include/c++/14.0.1/vector:144:29: required from =E2=80=98c= onstexpr > typename std::__debug::vector<_Tp, _Allocator>::size_type > std::erase(__debug::vector<_Tp, _Alloc>&, const _Up&) [with _Tp =3D const > void*; _Alloc =3D allocator; _Up =3D const void*; typename > __debug::vector<_Tp, _Allocator>::size_type =3D long unsigned int]=E2=80= =99 > > 144 | __cont.erase(__niter_wrap(__cont.begin(), __removed), > > | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ > > test.cc:4:15: required from here > > 4 | std::erase(v, p); > > | ~~~~~~~~~~^~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h:347:30: error: no > match for =E2=80=98operator-=E2=80=99 (operand types are > =E2=80=98__gnu_cxx::__normal_iterator void*, std::allocator > >=E2=80=99 and =E2=80=98const void**= =E2=80=99) > > 347 | { return __from + (__res - std::__niter_base(__from)); } > > | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > In file included from > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h:67: > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1148:7: note: > candidate: =E2=80=98constexpr __gnu_cxx::__normal_iterator<_Iterator, _Co= ntainer> > __gnu_cxx::__normal_iterator<_Iterator, > _Container>::operator-(difference_type) const [with _Iterator =3D const > void**; _Container =3D std::__cxx1998::vector std::allocator >; difference_type =3D long int]=E2=80=99 (ne= ar match) > > 1148 | operator-(difference_type __n) const _GLIBCXX_NOEXCEPT > > | ^~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1148:7: note: > conversion of argument 1 would be ill-formed: > > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h:347:49: error: invalid > conversion from =E2=80=98const void**=E2=80=99 to =E2=80=98__gnu_cxx::__n= ormal_iterator void**, std::__cxx1998::vector > > >::difference_type=E2=80=99 {aka =E2=80=98long int=E2=80=99} [-fpermissiv= e] > > 347 | { return __from + (__res - std::__niter_base(__from)); } > > | ~~~~~~~~~~~~~~~~~^~~~~~~~ > > | | > > | const void** > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:618:5: note: > candidate: =E2=80=98template constexp= r decltype > ((__y.base() - __x.base())) std::operator-(const > reverse_iterator<_IteratorL>&, const reverse_iterator<_IteratorR>&)=E2=80= =99 > > 618 | operator-(const reverse_iterator<_IteratorL>& __x, > > | ^~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:618:5: note: > template argument deduction/substitution failed: > > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h:347:30: note: > =E2=80=98__gnu_cxx::__normal_iterator void*, std::allocator > >=E2=80=99 is not derived from =E2= =80=98const > std::reverse_iterator<_IteratorL>=E2=80=99 > > 347 | { return __from + (__res - std::__niter_base(__from)); } > > | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1789:5: note: > candidate: =E2=80=98template constexp= r decltype > ((__x.base() - __y.base())) std::operator-(const > move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)=E2=80=99 > > 1789 | operator-(const move_iterator<_IteratorL>& __x, > > | ^~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1789:5: note: > template argument deduction/substitution failed: > > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h:347:30: note: > =E2=80=98__gnu_cxx::__normal_iterator void*, std::allocator > >=E2=80=99 is not derived from =E2= =80=98const > std::move_iterator<_IteratorL>=E2=80=99 > > 347 | { return __from + (__res - std::__niter_base(__from)); } > > | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1312:5: note: > candidate: =E2=80=98template > constexpr decltype ((__lhs.base() - __rhs.base())) > __gnu_cxx::operator-(const __normal_iterator<_IteratorL, _Container>&, > const __normal_iterator<_IteratorR, _Container>&)=E2=80=99 > > 1312 | operator-(const __normal_iterator<_IteratorL, _Container>& > __lhs, > > | ^~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1312:5: note: > template argument deduction/substitution failed: > > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h:347:30: note: > mismatched types =E2=80=98const __gnu_cxx::__normal_iterator<_IteratorR, > _Container>=E2=80=99 and =E2=80=98const void**=E2=80=99 > > 347 | { return __from + (__res - std::__niter_base(__from)); } > > | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1325:5: note: > candidate: =E2=80=98template constexpr= typename > __gnu_cxx::__normal_iterator<_Iterator, _Container>::difference_type > __gnu_cxx::operator-(const __normal_iterator<_Iterator, _Container>&, con= st > __normal_iterator<_Iterator, _Container>&)=E2=80=99 > > 1325 | operator-(const __normal_iterator<_Iterator, _Container>& > __lhs, > > | ^~~~~~~~ > > ~/gcc/inst/include/c++/14.0.1/bits/stl_iterator.h:1325:5: note: > template argument deduction/substitution failed: > > ~/gcc/inst/include/c++/14.0.1/bits/stl_algobase.h:347:30: note: > mismatched types =E2=80=98const __gnu_cxx::__normal_iterator<_Iterator, > _Container>=E2=80=99 and =E2=80=98const void**=E2=80=99 > > 347 | { return __from + (__res - std::__niter_base(__from)); } > > | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > --00000000000086bcb20611b7a82d--