public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10932] libstdc++: Add valid range checks to std::span constructors [PR98421] Date: Wed, 3 Aug 2022 12:30:57 +0000 (GMT) [thread overview] Message-ID: <20220803123057.92AC83885522@sourceware.org> (raw) https://gcc.gnu.org/g:de802e4736613a585dcfd508acf73033f18aa4da commit r10-10932-gde802e4736613a585dcfd508acf73033f18aa4da Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Aug 31 17:34:51 2021 +0100 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. (cherry picked from commit ef7becc9c8a48804d3fd9dac032f7b33e561a612) Diff: --- libstdc++-v3/include/std/span | 2 ++ .../testsuite/23_containers/span/cons_1_assert_neg.cc | 14 ++++++++++++++ .../testsuite/23_containers/span/cons_2_assert_neg.cc | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index 35df1a64c0e..b2a1ea3f0a2 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -165,6 +165,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> @@ -180,6 +181,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:[~2022-08-03 12:30 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=20220803123057.92AC83885522@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@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: linkBe 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).