From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id C3BC9396DC2A; Tue, 31 May 2022 18:39:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3BC9396DC2A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10809] libstdc++: invalid default init in _CachedPosition [PR101231] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 22b86cdc4d7fddb4991a08515e47e66fe5c41def X-Git-Newrev: 656cd10436260de997f5202b6737c7b8aebdfb4f Message-Id: <20220531183944.C3BC9396DC2A@sourceware.org> Date: Tue, 31 May 2022 18:39:44 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2022 18:39:44 -0000 https://gcc.gnu.org/g:656cd10436260de997f5202b6737c7b8aebdfb4f commit r10-10809-g656cd10436260de997f5202b6737c7b8aebdfb4f Author: Patrick Palka Date: Fri Jul 16 09:44:42 2021 -0400 libstdc++: invalid default init in _CachedPosition [PR101231] 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) Diff: --- 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 4c08de39c1d..17018a5616c 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1356,7 +1356,7 @@ namespace views _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 77df686aa4a..a43a4c851f8 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(); }