From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 2FE5A3858CD1 for ; Tue, 12 Mar 2024 00:54:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2FE5A3858CD1 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 2FE5A3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710204887; cv=none; b=R9jzz4S33s10ParyrMOTnhrM3BRc7pHdW2Yu3YjAjI0UpuIfgQG+RUtl9EKv2IfZ7I1WgtROGrmqPOcuwoD4dd2iJrfBlLak+R6HZsBZjlslZV9tXyjnCFBqs2r7BIWODv8+bD/NgfQi4BuUh6IHbQMLbcKDoS42oWltViD9NFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710204887; c=relaxed/simple; bh=oSPAvMu1dv9AMVCIvgnxd6ecXeNwsk2y+FjQwA1Lp18=; h=DKIM-Signature:From:Mime-Version:Subject:Date:To:Message-Id; b=jeX+f7GzoqUb70s0CniAAGBlJJXbEFuRihBCphfjvnDIwvMr4TNFa6MzLVxaZ7fl4IOsamlHDyQeEBhZc6aeqIbHwta0yjedTob6NbDEN7pzyx6NOmUAoDccL6FJsnIV6getCEI43V/oFbCKWWhEduL5Mfm4nY6sXRxu57zHAd0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5131a9b3d5bso4574722e87.0 for ; Mon, 11 Mar 2024 17:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710204881; x=1710809681; darn=gcc.gnu.org; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :from:to:cc:subject:date:message-id:reply-to; bh=1MtjSUSxInM04xLyh1D6C0PbK7lXYjuRRlcMwK8m5Js=; b=Jg2LXVr1dWW3SZm+ktTuqbs+EB0TgOnbsCKVO4RvglzXTrwTJqxO9KVRLq4h4aM+oq 5xAOLbjWF+mNv3pY7aOwmjXCWkwBsWBNf8AXs5LJrcmG/ResAAkdy2RB5FeavXFXeVRr tNleSH218Vjxd2+eWqiCgeuPBoP8MAcLBrtYvnIXr78FqsAgxEP5hij15ON7bGgaha+v Dfwkmyy61P3UtfesAOuVC6ff5clOScAwe/MJGi701v7oMfaZEFsDyhqo3Tg97Uvz4w7g X59/ak3yrHspyKlQE40bShfnOcMPIwVPLw68D/Wi5BUECz0wDjklg/gzoCdfB/iu8/nv Zcxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710204881; x=1710809681; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1MtjSUSxInM04xLyh1D6C0PbK7lXYjuRRlcMwK8m5Js=; b=F8HFTMfapt96zpzcpJ8pq8ltF3J3IlxTf5xDJZwSkUyKy+uNOHhTKmGTkZiBmuo1rq bFgmMFnDqwnSzlyoVY7iEot6MJDCXmYpvbxvyEafS+chLxSUSpVy7LfEcYBeMeaelx9F YZDOTDnRXOZE9mnvS3x6zMSBzHuewxsutorll7HOwrs3JkZBu1kt5Q1FPxiyGFNVnhep 5dQaVeWENzybujT6YR8D2R4Q3S/bB7IFv0nxebeUOSTzanNcfiv/uBYLA+MNoUxnr2xj CmMBVmwrDZHh59YVEay+3X+mdCzR4Xdbn7Mu9xE05IsYCrFucT1NjunqpHjNCZzePwfF 9S2w== X-Gm-Message-State: AOJu0YxjVEXVWOXsx+N3UnHp++MBFYgwYlFG9KlnZu6X/uLeovmeKDoJ 8F+tmOxYVZ/5rxXatFtqKR8kfqk5g6ZyYk/lvVycOzZ2S4rMaC+7uUSg9yFd X-Google-Smtp-Source: AGHT+IGgkNBy1+i5520FH0eQA9kdGgTK0MK2RBbpKyi7ySjP0EmomDUdnmZLXSHtb7wTsmpHf1RKgw== X-Received: by 2002:a05:6512:200c:b0:513:3d25:d2ed with SMTP id a12-20020a056512200c00b005133d25d2edmr3993518lfb.34.1710204881174; Mon, 11 Mar 2024 17:54:41 -0700 (PDT) Received: from smtpclient.apple (89-74-210-109.dynamic.chello.pl. [89.74.210.109]) by smtp.gmail.com with ESMTPSA id l4-20020a056512110400b00513ad31a00csm565106lfg.69.2024.03.11.17.54.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2024 17:54:40 -0700 (PDT) From: Maciej Miera Content-Type: multipart/alternative; boundary="Apple-Mail=_8D03CBCF-3F5B-4C13-A471-610F1F608441" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.4\)) Subject: Re: _LIBCXX_DEBUG value initialized singular iterators assert failures in std algorithms Date: Tue, 12 Mar 2024 01:54:39 +0100 References: <73AC0523-2237-46FD-9885-7AE3F8663DF2@gmail.com> To: libstdc++@gcc.gnu.org In-Reply-To: Message-Id: <28CE4FD1-FFB0-4300-81CA-C3CB07E436A6@gmail.com> X-Mailer: Apple Mail (2.3696.120.41.1.4) X-Spam-Status: No, score=2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --Apple-Mail=_8D03CBCF-3F5B-4C13-A471-610F1F608441 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Wiadomo=C5=9B=C4=87 napisana przez Jonathan Wakely w= dniu 11.03.2024, o godz. 21:40: >=20 > On Mon, 11 Mar 2024 at 20:07, Maciej Miera > wrote: >>=20 >> Hello, >>=20 >> I have tried to introduce an extra level of safety to my codebase and ut= ilize _GLIBCXX_DEBUG in my test builds in order to catch faulty iterators. >> However, I have encountered the following problem: I would like to utili= ze singular, value-initialized iterators as an arbitrary "null range=E2=80= =9D. >> However, this leads to failed assertions in std:: algorithms taking such= range. >>=20 >> Consider the following code sample with find_if: >>=20 >> #include >> #include >> #include >>=20 >> #ifndef __cpp_lib_null_iterators >> #warning "Not standard compliant" >> #endif >>=20 >> int main() >> { >> std::multimap::iterator it1{}; >> std::multimap::iterator it2{}; >>=20 >> (void) (it1=3D=3Dit2); // OK >> (void) std::find_if( >> it1, it2, [](const auto& el) { return el.second =3D=3D 8;}); >> } >>=20 >> Compiled with -std=3Dc++20 and -D_GLIBCXX_DEBUG it produces the warning = "Not standard compliant" >> and the execution results in the following assert failure: >>=20 >> /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_algo.h:387= 5: >> In function: >> constexpr _IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIte= r =3D >> gnu_debug::_Safe_iterator<_Rb_tree_iterator >, >> debug::multimap, bidirectional_iterator_tag>; _Predicate = =3D >> main()::] >>=20 >> 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? >=20 > 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=3D98466 and > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D70303 > 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 =3D=3D wor= ks fine. The feature check macro without _GLIBCXX_DEBUG and with = included is also fine. Maybe the need to include a header is the issue, bu= t that=E2=80=99s not the core of the problem anyway. The actual question is though, whether passing singular iterators to std al= gorithms (like find_if) should make the asserts at the beginning of the alg= o function fail when compiled with _GLIBCXX_DEBUG. IMHO, intuitively it sho= uld not, as comparing iterators equal would just ensure early exit and retu= rn 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).=20 What bothers me is whether the empty virtual range limited by two same sing= ular iterators is actually valid or not. This occurs with various std containers, I did check vector, multimap and u= nordered_map; I can check all the containers but I daresay it=E2=80=99s a p= retty general thing. Best regards, A. M. Miera= --Apple-Mail=_8D03CBCF-3F5B-4C13-A471-610F1F608441--