From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 299533858D38; Sat, 16 Mar 2024 12:16:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 299533858D38 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 299533858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710591392; cv=none; b=NDRgpz3McU5O80Y/cmHDyLDVthkvh5psKY9xMPhDyf3UCSwGNL3mcLQTnZeZ4DiHd2Sc4QAMC5wvo6jvCqBvxdqaZOr1HwdhxBvlDNHrsl1pfxUQ1yInHL0NP7UX7uUY11OyN6qmqoY8mqNEVEVY8eyYnDyTxP+Sq81iCRvRQ/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710591392; c=relaxed/simple; bh=wK6jWB/GApVGKEE0cpn7+gTAmTiou3TE89oEQOXdAb0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=SNn19fqpStMfhy5v0OPwrXS+OiD87png8iRPp1VROTv0YNCV8/efbtQadipuLDX7aCVioSHnanJXkQq8+M+uqQgPgvlpGAla4sfoRP5Oj8GJNOkUNTJxY88lS+CM7AzNL/mRLVfkBByCpNgPN85NosQFHvzrtGRGcLV0/OTQlEQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-41409fd8b6bso558645e9.1; Sat, 16 Mar 2024 05:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710591389; x=1711196189; darn=gcc.gnu.org; h=in-reply-to:content-language:references:cc:to:from:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=h8sY76lUUivIegTqSPX/SPk46jD6GEcm1AOFvvsQHl8=; b=IY5aakfMrIuZ82IbILm3AwxWBy4VHjEokn25du46KWSTUNHblJ9sgkHY6ZqqUOEHt6 QLV9Eti1qV1kVnsRxz2kvloeFbD6IGWO9so4rKhJJr7gbemTq4igsYKBIGUIq7zRAvtR 8WDNFv5K3Ddh9j9Xan0tX4K1+5AsXnMX1hw1Po4Kn/Vu7/f7JrYdAfV8YLSIJyLV3/Sc 9ksrIgpC/ryfBLYCYyttAc7Wf8sFG5og8ghQRUZInoC8VgnIoKsa7pukRsUHFfZWknSM 7oayRKOk2QlvWnrfbnk6xg1ro0j+XqbzzmlWXSnrfjqxZG+EsgxLqQ7JbBf5za2aVe+6 oKEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710591389; x=1711196189; h=in-reply-to:content-language:references:cc:to:from:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=h8sY76lUUivIegTqSPX/SPk46jD6GEcm1AOFvvsQHl8=; b=jEVtRpTDJlG/qZb61nQwYDBiQHzhBAIJ4xEeY4tnt3Q5qaSarrwqN6oGZQfbIknchH glx2D+8UBNkL40c6dcGOMlE942q65kJjGgICtzZYldCEbjX3oub2wJtKoVKeLpGKBSUg aOIVYqDh7P79JOTYfdSGfyKMPy2ijjQ+BB9HW+z61xdxvQVpBNUkfOqWGxQ7SUAyxvU9 qdrgB6eXUDNxYMkvxZy89hfSgXTudilFdp9QlQmHEPkO27hVC8wvUojFNoyWTUf/gadW S8vuNbSWXoRLsRlxvht1NDjEh4B6gDsrQpoem6A6/c0icaY42W1Tx5KzMiOBTYqclDMs Do9A== X-Forwarded-Encrypted: i=1; AJvYcCXHFbPXXQ+nviIbbBBL5vurxngGnrem/Dn0vztAyZL5xJpEjKc96cGK5bLriV8GxnPW1jwJDQXPjl0U1Twws8wHKKgq6/mCJw== X-Gm-Message-State: AOJu0YxXLrqdKUXEVFBb/CZPezIlJvqcEkNQhLqJVTf/0MvXNqg+mNFE JXcLQtdYDq0PLME5yRQugoHBmFJ5km7yH5nm6AOk9bmL1PeWzz1D X-Google-Smtp-Source: AGHT+IFjm1U+DeAFguCBCkyMkMFazu5S/7HtDtT777rlxXVNmcp0OzXlJPwWBzwhWcGKfUA+YjnszQ== X-Received: by 2002:a05:600c:54ef:b0:413:f1c0:f329 with SMTP id jb15-20020a05600c54ef00b00413f1c0f329mr4065254wmb.24.1710591388484; Sat, 16 Mar 2024 05:16:28 -0700 (PDT) Received: from ?IPV6:2a01:e0a:1dc:b1c0:1dd6:6959:2ee4:84fe? ([2a01:e0a:1dc:b1c0:1dd6:6959:2ee4:84fe]) by smtp.gmail.com with ESMTPSA id o9-20020adfe809000000b0033ec6ebf878sm5263901wrm.93.2024.03.16.05.16.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Mar 2024 05:16:25 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------fju0qn1TW3z4U2s33Vx2s8Lm" Message-ID: <2f29d2f2-a21b-42bb-997f-3918935d0dba@gmail.com> Date: Sat, 16 Mar 2024 13:16:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: _LIBCXX_DEBUG value initialized singular iterators assert failures in std algorithms [PR104316] From: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= To: Jonathan Wakely , Maciej Miera Cc: libstdc++@gcc.gnu.org, gcc-patches References: <73AC0523-2237-46FD-9885-7AE3F8663DF2@gmail.com> <28CE4FD1-FFB0-4300-81CA-C3CB07E436A6@gmail.com> <19f5939a-9341-4237-90d9-4f1279f03a88@gmail.com> Content-Language: en-US In-Reply-To: <19f5939a-9341-4237-90d9-4f1279f03a88@gmail.com> X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URI_HEX 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: This is a multi-part message in MIME format. --------------fju0qn1TW3z4U2s33Vx2s8Lm Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit With the patch, sorry. On 14/03/2024 22:49, François Dumont wrote: > Hi > > This is what I started to do. > > For now I haven't touch to __cpp_lib_null_iterators definition as > _Safe_local_iterator still need some work. > > libstdc++: Implement N3644 on _Safe_iterator<> [PR114316] > > Consider range of value-initialized iterators as valid and empty. > > libstdc++-v3/ChangeLog: > >         PR libstdc++/114316 >         * include/debug/safe_iterator.tcc > (_Safe_iterator<>::_M_valid_range): >         First check if both iterators are value-initialized before > checking if >         singular. >         * testsuite/23_containers/set/debug/114316.cc: New test case. >         * testsuite/23_containers/vector/debug/114316.cc: New test case. > > Tested under Linux x86_64, ok to commit ? > > François > > > On 12/03/2024 10:52, Jonathan Wakely wrote: >> On Tue, 12 Mar 2024 at 01:03, Jonathan Wakely >> wrote: >>> On Tue, 12 Mar 2024 at 00:55, Maciej Miera >>> wrote: >>>> >>>> >>>> Wiadomość napisana przez Jonathan Wakely w >>>> dniu 11.03.2024, o godz. 21:40: >>>> >>>> On Mon, 11 Mar 2024 at 20:07, Maciej Miera >>>> wrote: >>>> >>>> >>>> Hello, >>>> >>>> I have tried to introduce an extra level of safety to my codebase >>>> and utilize _GLIBCXX_DEBUG in my test builds in order to catch >>>> faulty iterators. >>>> However, I have encountered the following problem: I would like to >>>> utilize singular, value-initialized iterators as an arbitrary "null >>>> range”. >>>> However, this leads to failed assertions in std:: algorithms taking >>>> such range. >>>> >>>> Consider the following code sample with find_if: >>>> >>>> #include >>>> #include >>>> #include >>>> >>>> #ifndef __cpp_lib_null_iterators >>>> #warning "Not standard compliant" >>>> #endif >>>> >>>> int main() >>>> { >>>>     std::multimap::iterator it1{}; >>>>     std::multimap::iterator it2{}; >>>> >>>>     (void) (it1==it2); // OK >>>>     (void) std::find_if( >>>>         it1, it2, [](const auto& el) { return el.second == 8;}); >>>> } >>>> >>>> Compiled with -std=c++20 and -D_GLIBCXX_DEBUG it produces the >>>> warning "Not standard compliant" >>>> and the execution results in the following assert failure: >>>> >>>> /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_algo.h:3875: >>>> >>>> In function: >>>>     constexpr _IIter std::find_if(_IIter, _IIter, _Predicate) [with >>>> _IIter = >>>> gnu_debug::_Safe_iterator<_Rb_tree_iterator >, >>>>     debug::multimap, bidirectional_iterator_tag>; >>>> _Predicate = >>>>     main()::] >>>> >>>> The question is though: is it by design, or is it just a mere >>>> oversight? The warning actually suggest the first option. >>>> If it is an intentional design choice, could you provide some >>>> rationale behind it, please? >>>> >>>> >>>> The macro was not defined because the C++14 rule wasn't implemented >>>> for debug mode, but that should have been fixed for GCC 11, according >>>> to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98466 and >>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70303 >>>> So we should be able to define macro now, except maybe it wasn't fixed >>>> for the RB tree containers. >>>> >>>> >>>> >>>> Just to make sure there are no misunderstandings: comparison via == >>>> works fine. The feature check macro without _GLIBCXX_DEBUG and with >>>> included is also fine. Maybe the need to include a >>>> header is the issue, but that’s not the core of the problem anyway. >>> No, it has nothing to do with the headers included. The feature test >>> macro is defined like so: >>> >>> # if (__cplusplus >= 201402L) && (!defined(_GLIBCXX_DEBUG)) >>> #  define __glibcxx_null_iterators 201304L >>> >>> It's a very deliberate choice to not define it when _GLIBCXX_DEBUG is >>> defined. But as I said, I think we should have changed that. >>> >>>> The actual question is though, whether passing singular iterators >>>> to std algorithms (like find_if) should make the asserts at the >>>> beginning of the algo function fail when compiled with >>>> _GLIBCXX_DEBUG. IMHO, intuitively it should not, as comparing >>>> iterators equal would just ensure early exit and return of the same >>>> singular iterator. >>>> This seems not to be the case though. The actual message is this: >>>> Error: the function requires a valid iterator range [first, last). >>>> What bothers me is whether the empty virtual range limited by two >>>> same singular iterators is actually valid or not. >>> Yes, it's valid. So the bug is in the __glibcxx_requires_valid_range >>> macro. >> Thanks for the bugzilla report: >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114316 >> We'll get it fixed! >> --------------fju0qn1TW3z4U2s33Vx2s8Lm Content-Type: text/plain; charset=UTF-8; name="pr104316.txt" Content-Disposition: attachment; filename="pr104316.txt" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL2xpYnN0ZGMrKy12My9pbmNsdWRlL2RlYnVnL3NhZmVfaXRlcmF0b3Iu dGNjIGIvbGlic3RkYysrLXYzL2luY2x1ZGUvZGVidWcvc2FmZV9pdGVyYXRvci50Y2MKaW5k ZXggYThiMjQyMzNlODUuLjRiMmJhZjI5ODBlIDEwMDY0NAotLS0gYS9saWJzdGRjKystdjMv aW5jbHVkZS9kZWJ1Zy9zYWZlX2l0ZXJhdG9yLnRjYworKysgYi9saWJzdGRjKystdjMvaW5j bHVkZS9kZWJ1Zy9zYWZlX2l0ZXJhdG9yLnRjYwpAQCAtMTk0LDYgKzE5NCwxMiBAQCBuYW1l c3BhY2UgX19nbnVfZGVidWcKIAkJICAgc3RkOjpwYWlyPGRpZmZlcmVuY2VfdHlwZSwgX0Rp c3RhbmNlX3ByZWNpc2lvbj4mIF9fZGlzdCwKIAkJICAgYm9vbCBfX2NoZWNrX2RlcmVmZXJl bmNlYWJsZSkgY29uc3QKICAgICB7CisgICAgICBpZiAoX01fdmFsdWVfaW5pdGlhbGl6ZWQo KSAmJiBfX3Jocy5fTV92YWx1ZV9pbml0aWFsaXplZCgpKQorCXsKKwkgIF9fZGlzdCA9IHN0 ZDo6bWFrZV9wYW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