From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add valid range checks to std::span constructors [PR98421]
Date: Tue, 31 Aug 2021 19:14:21 +0100 [thread overview]
Message-ID: <YS5xfZIBQn/63xJl@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 357 bytes --]
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/98421
* include/std/span (span(Iter, size_type), span(Iter, Iter)):
Add valid range checks.
* testsuite/23_containers/span/cons_1_assert_neg.cc: New test.
* testsuite/23_containers/span/cons_2_assert_neg.cc: New test.
Tested x86_64-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2447 bytes --]
commit ef7becc9c8a48804d3fd9dac032f7b33e561a612
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Aug 31 17:34:51 2021
libstdc++: Add valid range checks to std::span constructors [PR98421]
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/98421
* include/std/span (span(Iter, size_type), span(Iter, Iter)):
Add valid range checks.
* testsuite/23_containers/span/cons_1_assert_neg.cc: New test.
* testsuite/23_containers/span/cons_2_assert_neg.cc: New test.
diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span
index 21d8f6a43a6..be053e8ef38 100644
--- a/libstdc++-v3/include/std/span
+++ b/libstdc++-v3/include/std/span
@@ -160,6 +160,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
__glibcxx_assert(__count == _Extent);
}
+ __glibcxx_requires_valid_range(__first, __first + __count);
}
template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
@@ -175,6 +176,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
__glibcxx_assert((__last - __first) == _Extent);
}
+ __glibcxx_requires_valid_range(__first, __last);
}
template<size_t _ArrayExtent>
diff --git a/libstdc++-v3/testsuite/23_containers/span/cons_1_assert_neg.cc b/libstdc++-v3/testsuite/23_containers/span/cons_1_assert_neg.cc
new file mode 100644
index 00000000000..2f555125453
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/span/cons_1_assert_neg.cc
@@ -0,0 +1,14 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { xfail *-*-* } }
+// { dg-require-effective-target c++2a }
+
+#undef _GLIBCXX_DEBUG
+#define _GLIBCXX_DEBUG
+#include <span>
+#include <vector>
+
+int main()
+{
+ std::vector<int> v(2);
+ std::span<int, std::dynamic_extent> s(v.begin(), 3);
+}
diff --git a/libstdc++-v3/testsuite/23_containers/span/cons_2_assert_neg.cc b/libstdc++-v3/testsuite/23_containers/span/cons_2_assert_neg.cc
new file mode 100644
index 00000000000..efef0e608ba
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/span/cons_2_assert_neg.cc
@@ -0,0 +1,14 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { xfail *-*-* } }
+// { dg-require-effective-target c++2a }
+
+#undef _GLIBCXX_DEBUG
+#define _GLIBCXX_DEBUG
+#include <span>
+#include <vector>
+
+int main()
+{
+ std::vector<int> v(2), w(1);
+ std::span<int, std::dynamic_extent> s(v.begin(), w.end());
+}
reply other threads:[~2021-08-31 18:14 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=YS5xfZIBQn/63xJl@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).