mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 18:38:30 +08:00
More of P0600 - '[[nodiscard]] in the Library' mark empty() as nodiscard in string, string_view, and the free function std::empty(). Removed tabs from <string_view>, which is why the diff is so big.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@318328 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1791,30 +1791,39 @@ end(const _Cp& __c)
|
|||||||
|
|
||||||
#if _LIBCPP_STD_VER > 14
|
#if _LIBCPP_STD_VER > 14
|
||||||
template <class _Cont>
|
template <class _Cont>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
|
constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
|
||||||
|
|
||||||
template <class _Tp, size_t _Sz>
|
template <class _Tp, size_t _Sz>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
|
constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
|
||||||
|
|
||||||
template <class _Cont>
|
template <class _Cont>
|
||||||
|
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
|
constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
|
||||||
|
|
||||||
template <class _Tp, size_t _Sz>
|
template <class _Tp, size_t _Sz>
|
||||||
|
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
|
constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
|
||||||
|
|
||||||
template <class _Ep>
|
template <class _Ep>
|
||||||
|
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
|
constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
|
||||||
|
|
||||||
template <class _Cont> constexpr
|
template <class _Cont> constexpr
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
|
auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
|
||||||
|
|
||||||
template <class _Cont> constexpr
|
template <class _Cont> constexpr
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
|
auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
|
||||||
|
|
||||||
template <class _Tp, size_t _Sz>
|
template <class _Tp, size_t _Sz>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
|
constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
|
||||||
|
|
||||||
template <class _Ep>
|
template <class _Ep>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
|
constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -901,7 +901,8 @@ public:
|
|||||||
void shrink_to_fit() _NOEXCEPT {reserve();}
|
void shrink_to_fit() _NOEXCEPT {reserve();}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
void clear() _NOEXCEPT;
|
void clear() _NOEXCEPT;
|
||||||
_LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
||||||
|
bool empty() const _NOEXCEPT {return size() == 0;}
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
|
_LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
|
||||||
_LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
|
_LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
|
||||||
|
@@ -263,8 +263,8 @@ public:
|
|||||||
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
||||||
size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
|
size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
|
||||||
|
|
||||||
_LIBCPP_CONSTEXPR bool _LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
||||||
empty() const _NOEXCEPT { return __size == 0; }
|
bool empty() const _NOEXCEPT { return __size == 0; }
|
||||||
|
|
||||||
// [string.view.access], element access
|
// [string.view.access], element access
|
||||||
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
||||||
|
28
test/std/iterators/iterator.container/empty.array.fail.cpp
Normal file
28
test/std/iterators/iterator.container/empty.array.fail.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <iterator>
|
||||||
|
|
||||||
|
// <iterator>
|
||||||
|
// template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;
|
||||||
|
|
||||||
|
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||||
|
// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
int c[5];
|
||||||
|
std::empty(c); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <iterator>
|
||||||
|
|
||||||
|
// <iterator>
|
||||||
|
// template <class C> constexpr auto empty(const C& c) -> decltype(c.empty());
|
||||||
|
|
||||||
|
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||||
|
// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
std::vector<int> c;
|
||||||
|
std::empty(c); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <iterator>
|
||||||
|
|
||||||
|
// <iterator>
|
||||||
|
// template <class E> constexpr bool empty(initializer_list<E> il) noexcept;
|
||||||
|
|
||||||
|
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||||
|
// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
std::initializer_list<int> c = { 4 };
|
||||||
|
std::empty(c); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||||
|
}
|
28
test/std/strings/basic.string/string.capacity/empty.fail.cpp
Normal file
28
test/std/strings/basic.string/string.capacity/empty.fail.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <string>
|
||||||
|
|
||||||
|
// class deque
|
||||||
|
|
||||||
|
// bool empty() const noexcept;
|
||||||
|
|
||||||
|
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||||
|
// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
std::string c;
|
||||||
|
c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||||
|
}
|
@@ -9,17 +9,19 @@
|
|||||||
|
|
||||||
// <string>
|
// <string>
|
||||||
|
|
||||||
// bool empty() const;
|
// bool empty() const noexcept;
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
#include "min_allocator.h"
|
#include "min_allocator.h"
|
||||||
|
|
||||||
template <class S>
|
template <class S>
|
||||||
void
|
void
|
||||||
test(const S& s)
|
test(const S& s)
|
||||||
{
|
{
|
||||||
|
ASSERT_NOEXCEPT(s.empty());
|
||||||
assert(s.empty() == (s.size() == 0));
|
assert(s.empty() == (s.size() == 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,10 @@ void test1 () {
|
|||||||
|
|
||||||
{
|
{
|
||||||
SV sv1;
|
SV sv1;
|
||||||
|
ASSERT_NOEXCEPT(sv1.size());
|
||||||
|
ASSERT_NOEXCEPT(sv1.empty());
|
||||||
|
ASSERT_NOEXCEPT(sv1.max_size());
|
||||||
|
ASSERT_NOEXCEPT(sv1.length());
|
||||||
assert ( sv1.size() == 0 );
|
assert ( sv1.size() == 0 );
|
||||||
assert ( sv1.empty());
|
assert ( sv1.empty());
|
||||||
assert ( sv1.size() == sv1.length());
|
assert ( sv1.size() == sv1.length());
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <string_view>
|
||||||
|
|
||||||
|
// class string_view
|
||||||
|
|
||||||
|
// bool empty() const noexcept;
|
||||||
|
|
||||||
|
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||||
|
// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
std::string_view c;
|
||||||
|
c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||||
|
}
|
Reference in New Issue
Block a user