From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Improve diagnostics for misuses of output iterators
Date: Tue, 12 Oct 2021 16:50:10 +0100 [thread overview]
Message-ID: <YWWusqM+mKy7Unm6@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 352 bytes --]
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.
Tested powerpc64le-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1714 bytes --]
commit d9dfd7ad3e0196f60a3fc6df6d65a40fb905409f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Sep 29 21:19:36 2021
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 --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<typename _OutputIterator>
+ 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<typename _OutputIterator, typename _Distance>
+ void
+ __advance(_OutputIterator&, _Distance, output_iterator_tag) = delete;
+#endif
+
/**
* @brief A generalization of pointer arithmetic.
* @param __i An input iterator.
reply other threads:[~2021-10-12 15:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=YWWusqM+mKy7Unm6@redhat.com \
--to=jwakely@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).