From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id A72F5385741C; Tue, 12 Oct 2021 15:49:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A72F5385741C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-4355] libstdc++: Improve diagnostics for misuses of output iterators X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 8226f6383a347371490897dba0383a7bc7082374 X-Git-Newrev: d9dfd7ad3e0196f60a3fc6df6d65a40fb905409f Message-Id: <20211012154949.A72F5385741C@sourceware.org> Date: Tue, 12 Oct 2021 15:49:49 +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, 12 Oct 2021 15:49:49 -0000 https://gcc.gnu.org/g:d9dfd7ad3e0196f60a3fc6df6d65a40fb905409f commit r12-4355-gd9dfd7ad3e0196f60a3fc6df6d65a40fb905409f Author: Jonathan Wakely Date: Wed Sep 29 21:19:36 2021 +0100 libstdc++: Improve diagnostics for misuses of output iterators This adds deleted overloads so that the errors for invalid uses of std::advance and std::distance are easier to understand (see for example PR 102181). libstdc++-v3/ChangeLog: * include/bits/stl_iterator_base_funcs.h (__advance): Add deleted overload to improve diagnostics. (__distance): Likewise. Diff: --- libstdc++-v3/include/bits/stl_iterator_base_funcs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h index e5afab7f4fd..fc6e9880de3 100644 --- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h +++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h @@ -119,6 +119,13 @@ _GLIBCXX_END_NAMESPACE_CONTAINER input_iterator_tag); #endif +#if __cplusplus >= 201103L + // Give better error if std::distance called with a non-Cpp17InputIterator. + template + void + __distance(_OutputIterator, _OutputIterator, output_iterator_tag) = delete; +#endif + /** * @brief A generalization of pointer arithmetic. * @param __first An input iterator. @@ -186,6 +193,13 @@ _GLIBCXX_END_NAMESPACE_CONTAINER __i += __n; } +#if __cplusplus >= 201103L + // Give better error if std::advance called with a non-Cpp17InputIterator. + template + void + __advance(_OutputIterator&, _Distance, output_iterator_tag) = delete; +#endif + /** * @brief A generalization of pointer arithmetic. * @param __i An input iterator.