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.129.124]) by sourceware.org (Postfix) with ESMTPS id 777333858C3A for ; Thu, 10 Feb 2022 16:56:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 777333858C3A Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-251-Ns80EbR6NdGJdGSWQupyzw-1; Thu, 10 Feb 2022 11:56:30 -0500 X-MC-Unique: Ns80EbR6NdGJdGSWQupyzw-1 Received: by mail-qt1-f199.google.com with SMTP id x10-20020ac8700a000000b002c3ef8fc44cso4829838qtm.8 for ; Thu, 10 Feb 2022 08:56:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jZ1Zoi8TgwAr0mt07a+pv6umtJMQS/o4h/16h+ZLntU=; b=Z4XPTtQpjY7XCWPIc6jZXgwT1zoOSRyp2sJNXC6Vh5f28zrpspTxVIj/y80B9Rbixa WFmTTTd17mEbc/G0NtaC+2gui1HAgkXRmqADVKWwyIhCS58JpD6rG8xMutX/ti7JeApN 9FZ41D7wuoaNtDB9S7gSmccABddPOFVv4vMy4ee7J/XQn6jaBIqWCLTyXEa7YMAUT362 kKLOO+WCWG0z4PhpEjjO8rxZ31Mp9oIrMBDSwPeqPRCBff2LwdBOmU2UBzKo0WbTQ6dH ekjLOFNfr4W2cmOwfHNuW4zLPVtCzVQ3kNHBlHWRgCetHoc5LdLgzGNTqC+s8tNfdrxT 9z9g== X-Gm-Message-State: AOAM531q0JcTic4QIeeTp/Fz2A65nIsJXcawnCpah9tLjUv9pix4cH1t ac62SHV2od3qFWjc5PESsm1cEaqcWiMa9SildiQZ7CXWu0wib5ShkWKJmx7U0vN4x+R2SlkwhF6 G4sn1DhWXXspqTH4= X-Received: by 2002:a05:6214:b6d:: with SMTP id ey13mr5381511qvb.40.1644512189621; Thu, 10 Feb 2022 08:56:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXgnV62MyJH+5RNfg0oyEXbXh07PVkmnKXgTeBXs5mcj6NpJHePxeiTnbeVptd/DIHXThVVQ== X-Received: by 2002:a05:6214:b6d:: with SMTP id ey13mr5381501qvb.40.1644512189452; Thu, 10 Feb 2022 08:56:29 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id x18sm11474453qtw.93.2022.02.10.08.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 08:56:29 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 3/3, 11 backport] libstdc++: invalid default init in _CachedPosition [PR101231] Date: Thu, 10 Feb 2022 11:56:24 -0500 Message-Id: <20220210165624.2953676-3-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.102.g2b9c120970 In-Reply-To: <20220210165624.2953676-1-ppalka@redhat.com> References: <20220210165624.2953676-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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, 10 Feb 2022 16:56:32 -0000 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. PR libstdc++/103904 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. (cherry picked from commit 1af937eb6246ad7f63ebff03590e9eede33aca81) --- 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 bf6cfae2a6e..a4228ba9aa0 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1221,7 +1221,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 af76a1ab39e..f5c0c2a6bb0 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) + ; +} + void test06() { @@ -99,5 +110,6 @@ main() test02(); test03(); test04(); + test05(); test06(); } -- 2.35.1.102.g2b9c120970