span constructor no address (#723)

* Changed &arr[0] to std::array<T, N>::data and std::address_of to protect against overloaded operator&.

* Removed the usage of `std::addressof` because it is a C++ 17 feature. Using decay for C arrays instead.

* Add unit tests for #662.

* Added c++17 test configurations for clang5.0 and clang6.0

* fixed CppCoreCheck pointer decay warning
This commit is contained in:
Anna Gringauze authored and Neil MacIntosh committed 2018-08-19 17:10:53 -07:00
1 parent 585f48ce55
commit 1995e86d1a
2 files changed
+42 -17

No files matched your search

+4 -3
View File
@@ -29,6 +29,7 @@
#include <stdexcept>
#include <type_traits> // for enable_if_t, declval, is_convertible, inte...
#include <utility>
#include <memory> // for std::addressof
#ifdef _MSC_VER
#pragma warning(push)
@@ -390,19 +391,19 @@ public:
template <std::size_t N>
constexpr span(element_type (&arr)[N]) noexcept
: storage_(KnownNotNull{&arr[0]}, details::extent_type<N>())
: storage_(KnownNotNull{std::addressof(arr[0])}, details::extent_type<N>())
{}
template <std::size_t N, class ArrayElementType = std::remove_const_t<element_type>>
// GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug
constexpr span(std::array<ArrayElementType, N>& arr) noexcept
: storage_(&arr[0], details::extent_type<N>())
: storage_(arr.data(), details::extent_type<N>())
{}
template <std::size_t N>
// GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug
constexpr span(const std::array<std::remove_const_t<element_type>, N>& arr) noexcept
: storage_(&arr[0], details::extent_type<N>())
: storage_(arr.data(), details::extent_type<N>())
{}
// NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement