From 389cd88ce797e2a4345eab8db478a3b8eba798e8 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 27 Jan 2020 10:30:03 +0000 Subject: [PATCH] libstdc++: Fix deduction guide for std::span (PR93426) The deduction guide from an iterator and sentinel used the wrong alias template and so didn't work. PR libstdc++/93426 * include/std/span (span): Fix deduction guide. * testsuite/23_containers/span/deduction.cc: New test. --- libstdc++-v3/ChangeLog | 6 ++ libstdc++-v3/include/std/span | 4 +- .../testsuite/23_containers/span/deduction.cc | 84 +++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/span/deduction.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0067e581acb..2b877a8b44d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2020-01-27 Jonathan Wakely + + PR libstdc++/93426 + * include/std/span (span): Fix deduction guide. + * testsuite/23_containers/span/deduction.cc: New test. + 2020-01-24 Jonathan Wakely * libsupc++/compare (__cmp_cat::_Eq): Remove enumeration type. diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index 0dae18672af..0072010dea8 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -190,7 +190,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : span(static_cast(__arr.data()), _ArrayExtent) { } - public: template requires (_Extent == dynamic_extent) && (!__detail::__is_std_span>::value) @@ -404,6 +403,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; // deduction guides + template span(_Type(&)[_ArrayExtent]) -> span<_Type, _ArrayExtent>; @@ -416,7 +416,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template span(_Iter, _Sentinel) - -> span>>; + -> span>>; template span(_Range &&) diff --git a/libstdc++-v3/testsuite/23_containers/span/deduction.cc b/libstdc++-v3/testsuite/23_containers/span/deduction.cc new file mode 100644 index 00000000000..66e955e961b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/span/deduction.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +template +constexpr bool is_static_span(const U&) +{ + return std::is_same_v, U> && N != std::dynamic_extent; +} + +template +constexpr bool is_dynamic_span(const U&) +{ + return std::is_same_v, U>; +} + +struct Range +{ + float* begin() const; + float* end() const; +}; + +void +test01() +{ + const char c[] = ""; + int i[2]{}; + std::array a; + Range r; + + std::span s1(c); + static_assert( is_static_span(s1) ); + + std::span s2(i); + static_assert( is_static_span(s2) ); + + std::span s3(a); + static_assert( is_static_span(s3) ); + + std::span s4(const_cast&>(a)); + static_assert( is_static_span(s4) ); + + std::span s5(std::begin(i), std::end(i)); + static_assert( is_dynamic_span(s5) ); + + std::span s6(std::cbegin(i), std::cend(i)); + static_assert( is_dynamic_span(s6) ); + + std::span s7(r); + static_assert( is_dynamic_span(s7) ); + + std::span s8(s1); + static_assert( is_static_span(s8) ); + + std::span s9(s2); + static_assert( is_static_span(s9) ); + + std::span s10(const_cast&>(s2)); + static_assert( is_static_span(s10) ); + + std::span s11(s5); + static_assert( is_dynamic_span(s11) ); + + std::span s12(const_cast&>(s5)); + static_assert( is_dynamic_span(s12) ); +} -- 2.30.2