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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E566838582B0 for ; Tue, 12 Mar 2024 09:53:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E566838582B0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E566838582B0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710237189; cv=none; b=Zc1/u5LynFBLq1bEYmwTmCdFZltiQCJpbA62Ep6iUJV3kolf64Uo5DKPjXE6zBpVbOlxVHVWcRYPJmp84/meRd9yahecBh2ckuzIkH7LL9Fxq6+h0Djn7LyUGVV+Fs3yrQfVDqdE2a8g0R9hraBrqa9YdqJQr1gPsMhLGoUiD2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710237189; c=relaxed/simple; bh=gRL8MriZ0fBDi/OPYGnvaxYqaVXCNwprGv1G+HtoODU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=cbx6fZwiJuRNiq1GHXWlYDXo5Rb622Lx/nROfn+5KaxNHe0+HAa1Z8n2onaz0YkC5DP31SMeVPTNIwgUKpKubY7zjopw9uvgLi2bLrJ2cctKaboz7ONk5769BTtj+2+Es+2aEb9zmz202Xuw7XPtriK2TkT9nje4z73wchRV6kU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710237186; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MQd6ZFnq2wq5GMwwGT5VRxVJIdvcS+9XFaeSJh6IBtE=; b=flUZpdwTnxpU/x/ht+F3A0qqyUp1rF5eiR/0Y1LEbyi3HrwkDuH1GGIS4+eSkjoyyVqnta 5EflkR9t3mUi9elJrFuYfaJTX6vPZA2kEaz1Tiaj5WLgqGq606yzVuq8k0EGy0EbAsbjqi NbDytPrAb6A5meVHPTF+UpR74cXS8uM= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-58-MfWkcuA0PBOKVOUM8Q6gew-1; Tue, 12 Mar 2024 05:53:05 -0400 X-MC-Unique: MfWkcuA0PBOKVOUM8Q6gew-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-60a605154d0so1717267b3.0 for ; Tue, 12 Mar 2024 02:53:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710237184; x=1710841984; h=content-transfer-encoding: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=MQd6ZFnq2wq5GMwwGT5VRxVJIdvcS+9XFaeSJh6IBtE=; b=HjZzapP3roLIk3so7RDIyr/PZwXflZrsrzz8ib2vY+T/2u2tDI+HSzG5q/4qVJD9dZ g98D0qmBh6UTXwR+3Q0veItzfecYnNZeEj7m5WyHS6OkzcqKcvpTozzg4bN9UIqNWd3U le86gr235Ynl8CGEKnG++jFF0H5X2PjZA6/sk8Io2EWnJIKiV2//Bul7TY3a6Weajvyb 3uoN2dVFRnM8dY2R2IxUggavNDOz7WLnJ2JKAZ1Srh4Wq8Yw0zuKmzeVbOmhbu9ioTtt YruITLlDNZAAcfsIydSBexGVYqhwmj+EMBB8zV/km9Bu3YIsovyl7h0xcFkzsDWRpAEE Nrkw== X-Gm-Message-State: AOJu0YwbzJw3xK35xoy7LgP+7BFxY5lYFHyY8nOAfBGMpji5EGC1sTxo 0IuvRm+c7xVNzVU+ggWWvzT1jIVm3jwNlXVTjCSFX9/eFGCfddse+7AFfkxpBrZJzok2T08pEnE tdOAsJXi+XAGht1wgwi/4iVGjj5Ja0p9JaO9uWBV67OmyD+lqXSQcJZ78ec+gQ7sb4lvlJ5iHSc f2lU9j3BnjT40/yjyCa1qAMu2Iv3k= X-Received: by 2002:a81:b667:0:b0:609:cf0d:9d64 with SMTP id h39-20020a81b667000000b00609cf0d9d64mr6296876ywk.13.1710237184565; Tue, 12 Mar 2024 02:53:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6xiUjETDX+w2YXFCWf8MJUVmO/dv+UvDRfTK+uGFCeM+tOrpZc1s1DI86ZXjz7UjsNLa17hrQaOqjlxB8p+8= X-Received: by 2002:a81:b667:0:b0:609:cf0d:9d64 with SMTP id h39-20020a81b667000000b00609cf0d9d64mr6296870ywk.13.1710237184233; Tue, 12 Mar 2024 02:53:04 -0700 (PDT) MIME-Version: 1.0 References: <73AC0523-2237-46FD-9885-7AE3F8663DF2@gmail.com> <28CE4FD1-FFB0-4300-81CA-C3CB07E436A6@gmail.com> In-Reply-To: From: Jonathan Wakely Date: Tue, 12 Mar 2024 09:52:48 +0000 Message-ID: Subject: Re: _LIBCXX_DEBUG value initialized singular iterators assert failures in std algorithms To: Maciej Miera Cc: libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: On Tue, 12 Mar 2024 at 01:03, Jonathan Wakely wrote: > > On Tue, 12 Mar 2024 at 00:55, Maciej Miera wrote= : > > > > > > > > Wiadomo=C5=9B=C4=87 napisana przez Jonathan Wakely = w dniu 11.03.2024, o godz. 21:40: > > > > On Mon, 11 Mar 2024 at 20:07, Maciej Miera wro= te: > > > > > > Hello, > > > > I have tried to introduce an extra level of safety to my codebase and u= tilize _GLIBCXX_DEBUG in my test builds in order to catch faulty iterators. > > However, I have encountered the following problem: I would like to util= ize singular, value-initialized iterators as an arbitrary "null range=E2=80= =9D. > > However, this leads to failed assertions in std:: algorithms taking suc= h 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=3D=3Dit2); // OK > > (void) std::find_if( > > it1, it2, [](const auto& el) { return el.second =3D=3D 8;}); > > } > > > > 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: > > > > /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_algo.h:38= 75: > > In function: > > constexpr _IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIt= er =3D > > gnu_debug::_Safe_iterator<_Rb_tree_iterator >, > > debug::multimap, bidirectional_iterator_tag>; _Predicate = =3D > > 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=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= 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=E2=80=99s 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 >=3D 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 st= d 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 macr= o. Thanks for the bugzilla report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114316 We'll get it fixed!