@@ -246,20 +246,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// observers
+ [[nodiscard]]
constexpr size_type
size() const noexcept
{ return this->_M_extent._M_extent(); }
+ [[nodiscard]]
constexpr size_type
size_bytes() const noexcept
{ return this->_M_extent._M_extent() * sizeof(element_type); }
- [[nodiscard]] constexpr bool
+ [[nodiscard]]
+ constexpr bool
empty() const noexcept
{ return size() == 0; }
// element access
+ [[nodiscard]]
constexpr reference
front() const noexcept
{
@@ -267,6 +271,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *this->_M_ptr;
}
+ [[nodiscard]]
constexpr reference
back() const noexcept
{
@@ -274,6 +279,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *(this->_M_ptr + (size() - 1));
}
+ [[nodiscard]]
constexpr reference
operator[](size_type __idx) const noexcept
{
@@ -281,41 +287,50 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *(this->_M_ptr + __idx);
}
+ [[nodiscard]]
constexpr pointer
data() const noexcept
{ return this->_M_ptr; }
// iterator support
+ [[nodiscard]]
constexpr iterator
begin() const noexcept
{ return iterator(this->_M_ptr); }
+ [[nodiscard]]
constexpr iterator
end() const noexcept
{ return iterator(this->_M_ptr + this->size()); }
+ [[nodiscard]]
constexpr reverse_iterator
rbegin() const noexcept
{ return reverse_iterator(this->end()); }
+ [[nodiscard]]
constexpr reverse_iterator
rend() const noexcept
{ return reverse_iterator(this->begin()); }
#if __cplusplus > 202002L
+ [[nodiscard]]
constexpr const_iterator
cbegin() const noexcept
{ return begin(); }
+ [[nodiscard]]
constexpr const_iterator
cend() const noexcept
{ return end(); }
+ [[nodiscard]]
constexpr const_reverse_iterator
crbegin() const noexcept
{ return rbegin(); }
+ [[nodiscard]]
constexpr const_reverse_iterator
crend() const noexcept
{ return rend(); }
@@ -324,6 +339,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// subviews
template<size_t _Count>
+ [[nodiscard]]
constexpr span<element_type, _Count>
first() const noexcept
{
@@ -335,6 +351,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Sp{ this->data(), _Count };
}
+ [[nodiscard]]
constexpr span<element_type, dynamic_extent>
first(size_type __count) const noexcept
{
@@ -343,6 +360,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<size_t _Count>
+ [[nodiscard]]
constexpr span<element_type, _Count>
last() const noexcept
{
@@ -354,6 +372,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Sp{ this->data() + (this->size() - _Count), _Count };
}
+ [[nodiscard]]
constexpr span<element_type, dynamic_extent>
last(size_type __count) const noexcept
{
@@ -362,6 +381,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<size_t _Offset, size_t _Count = dynamic_extent>
+ [[nodiscard]]
constexpr auto
subspan() const noexcept
-> span<element_type, _S_subspan_extent<_Offset, _Count>()>
@@ -393,6 +413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
+ [[nodiscard]]
constexpr span<element_type, dynamic_extent>
subspan(size_type __offset, size_type __count = dynamic_extent) const
noexcept
@@ -434,6 +455,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
-> span<remove_reference_t<ranges::range_reference_t<_Range&>>>;
template<typename _Type, size_t _Extent>
+ [[nodiscard]]
inline
span<const byte, _Extent == dynamic_extent
? dynamic_extent : _Extent * sizeof(_Type)>
@@ -451,7 +473,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline
span<byte, _Extent == dynamic_extent
? dynamic_extent : _Extent * sizeof(_Type)>
- as_writable_bytes(span<_Type, _Extent> __sp) noexcept
+ as_writable_bytes [[nodiscard]] (span<_Type, _Extent> __sp) noexcept
{
auto data = reinterpret_cast<byte*>(__sp.data());
auto size = __sp.size_bytes();
@@ -25,5 +25,5 @@
int main()
{
std::span<int, std::dynamic_extent> s;
- s.back();
+ (void) s.back();
}
@@ -24,7 +24,7 @@ test01(bool b)
{
std::span<int, 0> s;
if (b || !s.empty())
- s.back();
+ (void) s.back();
return true;
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.first(5);
+ (void) s.first(5);
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.first<5>();
+ (void) s.first<5>();
}
@@ -24,6 +24,6 @@ test01()
{
int a[4];
std::span<int, 4> s(a);
- s.first<5>(); // { dg-error "here" }
+ (void) s.first<5>(); // { dg-error "here" }
}
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
@@ -25,5 +25,5 @@
int main()
{
std::span<int, std::dynamic_extent> s;
- s.front();
+ (void) s.front();
}
@@ -24,7 +24,7 @@ test01(bool b)
{
std::span<int, 0> s;
if (b || !s.empty())
- s.front();
+ (void) s.front();
return true;
}
@@ -25,5 +25,5 @@
int main()
{
std::span<int, std::dynamic_extent> s;
- s[99];
+ (void) s[99];
}
@@ -24,7 +24,7 @@ test01(bool b)
{
std::span<int, 0> s;
if (b || !s.empty())
- s[99];
+ (void) s[99];
return true;
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.last(5);
+ (void) s.last(5);
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.last<5>();
+ (void) s.last<5>();
}
@@ -24,6 +24,6 @@ test01()
{
int a[2];
std::span<int, 2> s(a);
- s.last<3>(); // { dg-error "here" }
+ (void) s.last<3>(); // { dg-error "here" }
}
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
new file mode 100644
@@ -0,0 +1,58 @@
+// { dg-do compile { target c++20 } }
+
+#include <span>
+
+void
+test_observers(std::span<int> s)
+{
+ s.size(); // { dg-warning "ignoring return value" }
+ s.size_bytes(); // { dg-warning "ignoring return value" }
+ s.empty(); // { dg-warning "ignoring return value" }
+}
+
+void
+test_element_access(std::span<float> s)
+{
+ s.front(); // { dg-warning "ignoring return value" }
+ s.back(); // { dg-warning "ignoring return value" }
+ s[1]; // { dg-warning "ignoring return value" }
+ s.data(); // { dg-warning "ignoring return value" }
+}
+
+struct S { };
+
+void
+test_iterators(std::span<S> s)
+{
+ s.begin(); // { dg-warning "ignoring return value" }
+ s.end(); // { dg-warning "ignoring return value" }
+ s.rbegin(); // { dg-warning "ignoring return value" }
+ s.rend(); // { dg-warning "ignoring return value" }
+
+#if __cplusplus > 202002L
+ s.cbegin(); // { dg-warning "ignoring return value" "" { target c++23 } }
+ s.cend(); // { dg-warning "ignoring return value" "" { target c++23 } }
+ s.crbegin(); // { dg-warning "ignoring return value" "" { target c++23 } }
+ s.crend(); // { dg-warning "ignoring return value" "" { target c++23 } }
+#endif
+}
+
+void
+test_subviews(std::span<long, 20> s)
+{
+ s.first<5>(); // { dg-warning "ignoring return value" }
+ s.first(6); // { dg-warning "ignoring return value" }
+ s.last<7>(); // { dg-warning "ignoring return value" }
+ s.last(8); // { dg-warning "ignoring return value" }
+ s.subspan<1>(); // { dg-warning "ignoring return value" }
+ s.subspan<2, 3>(); // { dg-warning "ignoring return value" }
+ s.subspan(4); // { dg-warning "ignoring return value" }
+ s.subspan(5, 6); // { dg-warning "ignoring return value" }
+}
+
+void
+test_non_members(std::span<S, 20> s)
+{
+ std::as_bytes(s); // { dg-warning "ignoring return value" }
+ std::as_writable_bytes(s); // { dg-warning "ignoring return value" }
+}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.subspan<2, 5>();
+ (void) s.subspan<2, 5>();
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.subspan<2, 3>();
+ (void) s.subspan<2, 3>();
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.subspan(5, 0);
+ (void) s.subspan(5, 0);
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.subspan(2, 5);
+ (void) s.subspan(2, 5);
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.subspan(2, 3);
+ (void) s.subspan(2, 3);
}
@@ -26,5 +26,5 @@ int main()
{
int a[4];
std::span<int, std::dynamic_extent> s(a);
- s.subspan<5, 0>();
+ (void) s.subspan<5, 0>();
}
@@ -24,7 +24,7 @@ test01()
{
int a[4];
std::span<int, 4> s(a);
- s.subspan<5, 0>(); // { dg-error "here" }
+ (void) s.subspan<5, 0>(); // { dg-error "here" }
}
void
@@ -32,7 +32,7 @@ test02()
{
int a[4];
std::span<int, 4> s(a);
- s.subspan<3, 5>(); // { dg-error "here" }
+ (void) s.subspan<3, 5>(); // { dg-error "here" }
}
void
@@ -40,7 +40,7 @@ test03()
{
int a[4];
std::span<int, 4> s(a);
- s.subspan<3, 2>(); // { dg-error "here" }
+ (void) s.subspan<3, 2>(); // { dg-error "here" }
}
// { dg-error "static assertion failed" "" { target *-*-* } 0 }