diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-11-15 05:51:26 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-11-15 05:51:26 +0000 |
commit | 88626bf496e9a1276652790438b389e65950629f (patch) | |
tree | d975e9769477acff346690e7bfffa48a7ebd4ffc /test | |
parent | 2645a49a67cd23f82f3a431adeb4488ff7a53d55 (diff) |
First part of P0600 - '[[nodiscard] in the standard library'. Mark the 'empty()' methods of all the containers as nodiscard. If you're calling empty() w/o looking at the result, you probably meanto to call 'clear()'. c++2a only
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@318269 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
17 files changed, 476 insertions, 0 deletions
diff --git a/test/std/containers/associative/map/map.access/empty.fail.cpp b/test/std/containers/associative/map/map.access/empty.fail.cpp new file mode 100644 index 000000000..14ac13c99 --- /dev/null +++ b/test/std/containers/associative/map/map.access/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// 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 <map> + +#include "test_macros.h" + +int main () +{ + std::map<int, int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/associative/multimap/empty.fail.cpp b/test/std/containers/associative/multimap/empty.fail.cpp new file mode 100644 index 000000000..12ca05ef1 --- /dev/null +++ b/test/std/containers/associative/multimap/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// 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 <map> + +#include "test_macros.h" + +int main () +{ + std::multimap<int, int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/associative/multiset/empty.fail.cpp b/test/std/containers/associative/multiset/empty.fail.cpp new file mode 100644 index 000000000..2169a07e4 --- /dev/null +++ b/test/std/containers/associative/multiset/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// 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 <set> + +#include "test_macros.h" + +int main () +{ + std::multiset<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/associative/set/empty.fail.cpp b/test/std/containers/associative/set/empty.fail.cpp new file mode 100644 index 000000000..0eea6fb67 --- /dev/null +++ b/test/std/containers/associative/set/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// 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 <set> + +#include "test_macros.h" + +int main () +{ + std::set<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.fail.cpp b/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.fail.cpp new file mode 100644 index 000000000..c034f22b7 --- /dev/null +++ b/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// class priority_queue + +// 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 <queue> + +#include "test_macros.h" + +int main () +{ + std::priority_queue<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/container.adaptors/queue/queue.defn/empty.fail.cpp b/test/std/containers/container.adaptors/queue/queue.defn/empty.fail.cpp new file mode 100644 index 000000000..ce017d2dd --- /dev/null +++ b/test/std/containers/container.adaptors/queue/queue.defn/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// class queue + +// 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 <queue> + +#include "test_macros.h" + +int main () +{ + std::queue<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/empty.fail.cpp b/test/std/containers/container.adaptors/stack/stack.defn/empty.fail.cpp new file mode 100644 index 000000000..001a38fe3 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// class stack + +// 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 <stack> + +#include "test_macros.h" + +int main () +{ + std::stack<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/array/empty.fail.cpp b/test/std/containers/sequences/array/empty.fail.cpp new file mode 100644 index 000000000..85bf5a7c9 --- /dev/null +++ b/test/std/containers/sequences/array/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <array> + +// class array + +// 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 <array> + +#include "test_macros.h" + +int main () +{ + std::array<int, 1> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/deque/deque.capacity/empty.fail.cpp b/test/std/containers/sequences/deque/deque.capacity/empty.fail.cpp new file mode 100644 index 000000000..adfd5f2d8 --- /dev/null +++ b/test/std/containers/sequences/deque/deque.capacity/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// 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 <deque> + +#include "test_macros.h" + +int main () +{ + std::deque<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/forwardlist/empty.fail.cpp b/test/std/containers/sequences/forwardlist/empty.fail.cpp new file mode 100644 index 000000000..78928b480 --- /dev/null +++ b/test/std/containers/sequences/forwardlist/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// class forward_list + +// 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 <forward_list> + +#include "test_macros.h" + +int main () +{ + std::forward_list<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/list/list.capacity/empty.fail.cpp b/test/std/containers/sequences/list/list.capacity/empty.fail.cpp new file mode 100644 index 000000000..fe0387c83 --- /dev/null +++ b/test/std/containers/sequences/list/list.capacity/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <list> + +// class list + +// 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 <list> + +#include "test_macros.h" + +int main () +{ + std::list<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/vector.bool/empty.fail.cpp b/test/std/containers/sequences/vector.bool/empty.fail.cpp new file mode 100644 index 000000000..99c245d0c --- /dev/null +++ b/test/std/containers/sequences/vector.bool/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// class vector + +// 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 <vector> + +#include "test_macros.h" + +int main () +{ + std::vector<bool> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/vector/vector.capacity/empty.fail.cpp b/test/std/containers/sequences/vector/vector.capacity/empty.fail.cpp new file mode 100644 index 000000000..abfdfbfb9 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// class vector + +// 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 <vector> + +#include "test_macros.h" + +int main () +{ + std::vector<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/unord/unord.map/empty.fail.cpp b/test/std/containers/unord/unord.map/empty.fail.cpp new file mode 100644 index 000000000..1c67169bb --- /dev/null +++ b/test/std/containers/unord/unord.map/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// class unordered_map + +// 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 <unordered_map> + +#include "test_macros.h" + +int main () +{ + std::unordered_map<int, int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/unord/unord.multimap/empty.fail.cpp b/test/std/containers/unord/unord.multimap/empty.fail.cpp new file mode 100644 index 000000000..7e3a6f4b9 --- /dev/null +++ b/test/std/containers/unord/unord.multimap/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> + +// class unordered_multimap + +// 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 <unordered_map> + +#include "test_macros.h" + +int main () +{ + std::unordered_multimap<int, int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/unord/unord.multiset/empty.fail.cpp b/test/std/containers/unord/unord.multiset/empty.fail.cpp new file mode 100644 index 000000000..8e068a4e1 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// class unordered_multiset + +// 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 <unordered_set> + +#include "test_macros.h" + +int main () +{ + std::unordered_multiset<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/unord/unord.set/empty.fail.cpp b/test/std/containers/unord/unord.set/empty.fail.cpp new file mode 100644 index 000000000..23603c261 --- /dev/null +++ b/test/std/containers/unord/unord.set/empty.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> + +// class unordered_set + +// 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 <unordered_set> + +#include "test_macros.h" + +int main () +{ + std::unordered_set<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} |