From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH 3/3, 11 backport] libstdc++: invalid default init in _CachedPosition [PR101231]
Date: Thu, 10 Feb 2022 11:56:24 -0500 [thread overview]
Message-ID: <20220210165624.2953676-3-ppalka@redhat.com> (raw)
In-Reply-To: <20220210165624.2953676-1-ppalka@redhat.com>
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<It>);
}
+void
+test05()
+{
+ // PR libstdc++/101231
+ auto words = std::istringstream{"42"};
+ auto is = ranges::istream_view<int>(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
next prev parent reply other threads:[~2022-02-10 16:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-10 16:56 [PATCH 1/3, 11 backport] libstdc++: Implement P2325 changes to default-constructibility of views Patrick Palka
2022-02-10 16:56 ` [PATCH 2/3, 11 backport] libstdc++: Sync __cpp_lib_ranges macro defined in ranges_cmp.h Patrick Palka
2022-02-11 13:35 ` Jonathan Wakely
2022-02-10 16:56 ` Patrick Palka [this message]
2022-02-11 13:36 ` [PATCH 3/3, 11 backport] libstdc++: invalid default init in _CachedPosition [PR101231] Jonathan Wakely
2022-02-10 16:58 ` [PATCH 1/3, 11 backport] libstdc++: Implement P2325 changes to default-constructibility of views Patrick Palka
2022-02-10 17:27 ` Patrick Palka
2022-02-11 13:35 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220210165624.2953676-3-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).