From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 60783385BF84; Thu, 15 Jul 2021 19:59:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 60783385BF84 Received: by mail-wr1-x432.google.com with SMTP id d2so9391413wrn.0; Thu, 15 Jul 2021 12:59:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yg9tLcU4S19UwB9ZWEar+Su4sKpBI5r3OjLLIdt8nas=; b=GsgHdRIpR/LHUEpQdJA/rlzDYhhL70HVotqiWv7rJQ0qudbh1bQZl5bwhzPxWofEua Qk6GVxE1geCDL5haG7rvLt81DLwe17OPuHuz8LByqfm+FuRSX38h32/vxNWSrIGTc5X2 yYjJZETlwuv1VQDXW/zyTJbQCrERn2olqxoFgtEPfAQzCDJfMIgJXvxBfTym664ydPfG g2ZMLnMil4UiMiOBfHnKxT0m4rlgMdwXQLyMxa8nzTEsy8ntLbjz259gpB3mELlxA+1x UmOiqewx93JZZp1lXkHagr4dLbZVv69Nev/kaeYJGdegtdHpJe4KtZeOB8NdpzE6ilw3 wq3A== X-Gm-Message-State: AOAM532JkBoPcitN6vGPbBWIgWHwn2b8z5GePA8u8AsbtovXP1TRtvYw JsO2ha2AahyOXcMxtNmnnGs4nZcvBuB4K+bOe2k= X-Google-Smtp-Source: ABdhPJx1bnxYt18ZFPbNCdJ78rfvobvjJIHkBytBTFnPBDS91nhESXy24vqTekyBrVLgvKqSxqy8qROKnNopL7zxIJw= X-Received: by 2002:a5d:6ac8:: with SMTP id u8mr7827758wrw.30.1626379144372; Thu, 15 Jul 2021 12:59:04 -0700 (PDT) MIME-Version: 1.0 References: <20210713190721.659161-1-ppalka@redhat.com> In-Reply-To: <20210713190721.659161-1-ppalka@redhat.com> From: Jonathan Wakely Date: Thu, 15 Jul 2021 20:58:53 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: invalid default init in _CachedPosition [PR101231] To: Patrick Palka Cc: gcc-patches , "libstdc++" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: Thu, 15 Jul 2021 19:59:06 -0000 On Tue, 13 Jul 2021 at 20:09, Patrick Palka via Libstdc++ wrote: > > The primary template for _CachedPosition is a dummy implementation for > non-forward ranges, the iterators for which generally can't be cached. > Because this implementation doesn't actually cache anything, _M_has_value > is defined to be false and so calls to _M_get (which are always guarded > by _M_has_value) are unreachable. > > Still, to suppress a "control reaches end of non-void function" warning > I made _M_get return {}, but after P2325 input iterators are no longer > necessarily default constructible so this workaround now breaks valid > programs. > > This patch fixes this by instead using __builtin_unreachable to squelch > the warning. > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? Yes, thanks. > > PR libstdc++/101231 > > libstdc++-v3/ChangeLog: > > * include/std/ranges (_CachedPosition::_M_get): For non-forward > ranges, just call __builtin_unreachable. > * testsuite/std/ranges/istream_view.cc (test05): New test. > --- > libstdc++-v3/include/std/ranges | 2 +- > libstdc++-v3/testsuite/std/ranges/istream_view.cc | 12 ++++++++++++ > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges > index df74ac9dc19..d791e15d096 100644 > --- a/libstdc++-v3/include/std/ranges > +++ b/libstdc++-v3/include/std/ranges > @@ -1232,7 +1232,7 @@ namespace views::__adaptor > _M_get(const _Range&) const > { > __glibcxx_assert(false); > - return {}; > + __builtin_unreachable(); > } > > constexpr void > diff --git a/libstdc++-v3/testsuite/std/ranges/istream_view.cc b/libstdc++-v3/testsuite/std/ranges/istream_view.cc > index 369790e89e5..2f15f787250 100644 > --- a/libstdc++-v3/testsuite/std/ranges/istream_view.cc > +++ b/libstdc++-v3/testsuite/std/ranges/istream_view.cc > @@ -83,6 +83,17 @@ test04() > static_assert(!std::forward_iterator); > } > > +void > +test05() > +{ > + // PR libstdc++/101231 > + auto words = std::istringstream{"42"}; > + auto is = ranges::istream_view(words); > + auto r = is | views::filter([](auto) { return true; }); > + for (auto x : r) > + ; > +} > + > int > main() > { > @@ -90,4 +101,5 @@ main() > test02(); > test03(); > test04(); > + test05(); > } > -- > 2.32.0.170.gd486ca60a5 >