aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-11-23 22:11:21 +0000
committerJonathan Wakely <jwakely@redhat.com>2017-11-23 22:11:21 +0000
commitfc2cb58138fc5af1cc26d8fecdb58646b62fb9fb (patch)
treeaf98d60a7a26651eb974872fce8e8a47e0647e99
parenta3a238355c7810e31e7a693623f2e6c548a6e490 (diff)
Add [[nodiscard]] attribute to C++17 components
* include/bits/fs_path.h (path::empty): Add nodiscard attribute. * include/bits/range_access.h (empty): Likewise. * include/std/string_view (basic_string_view::empty): Likewise. * testsuite/21_strings/basic_string_view/capacity/empty_neg.cc: New test. * testsuite/24_iterators/range_access_cpp17_neg.cc: New test. * testsuite/27_io/filesystem/path/query/empty_neg.cc: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@255124 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/bits/fs_path.h2
-rw-r--r--libstdc++-v3/include/bits/node_handle.h2
-rw-r--r--libstdc++-v3/include/bits/range_access.h6
-rw-r--r--libstdc++-v3/include/std/string_view2
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/empty_neg.cc28
-rw-r--r--libstdc++-v3/testsuite/24_iterators/range_access_cpp17_neg.cc44
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/query/empty_neg.cc28
8 files changed, 114 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 099881afad1..3b2dad016fd 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,13 @@
2017-11-23 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/fs_path.h (path::empty): Add nodiscard attribute.
+ * include/bits/range_access.h (empty): Likewise.
+ * include/std/string_view (basic_string_view::empty): Likewise.
+ * testsuite/21_strings/basic_string_view/capacity/empty_neg.cc: New
+ test.
+ * testsuite/24_iterators/range_access_cpp17_neg.cc: New test.
+ * testsuite/27_io/filesystem/path/query/empty_neg.cc: New test.
+
PR libstdc++/83134
* include/std/type_traits (__not_): Explicitly convert to bool.
* testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error.
diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index 7d97cdfbb81..99740c9b383 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -370,7 +370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
// query
- bool empty() const noexcept { return _M_pathname.empty(); }
+ [[nodiscard]] bool empty() const noexcept { return _M_pathname.empty(); }
bool has_root_name() const;
bool has_root_directory() const;
bool has_root_path() const;
diff --git a/libstdc++-v3/include/bits/node_handle.h b/libstdc++-v3/include/bits/node_handle.h
index 4a830630c89..0d8dbeb4110 100644
--- a/libstdc++-v3/include/bits/node_handle.h
+++ b/libstdc++-v3/include/bits/node_handle.h
@@ -62,7 +62,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
explicit operator bool() const noexcept { return _M_ptr != nullptr; }
- bool empty() const noexcept { return _M_ptr == nullptr; }
+ [[nodiscard]] bool empty() const noexcept { return _M_ptr == nullptr; }
protected:
constexpr _Node_handle_common() noexcept : _M_ptr(), _M_alloc() {}
diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h
index 2a037ad8082..a5044f11976 100644
--- a/libstdc++-v3/include/bits/range_access.h
+++ b/libstdc++-v3/include/bits/range_access.h
@@ -257,7 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template <typename _Container>
- constexpr auto
+ [[nodiscard]] constexpr auto
empty(const _Container& __cont) noexcept(noexcept(__cont.empty()))
-> decltype(__cont.empty())
{ return __cont.empty(); }
@@ -267,7 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __array Container.
*/
template <typename _Tp, size_t _Nm>
- constexpr bool
+ [[nodiscard]] constexpr bool
empty(const _Tp (&/*__array*/)[_Nm]) noexcept
{ return false; }
@@ -276,7 +276,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __il Initializer list.
*/
template <typename _Tp>
- constexpr bool
+ [[nodiscard]] constexpr bool
empty(initializer_list<_Tp> __il) noexcept
{ return __il.size() == 0;}
diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view
index 1900b867841..fa834002726 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -160,7 +160,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/ sizeof(value_type) / 4;
}
- constexpr bool
+ [[nodiscard]] constexpr bool
empty() const noexcept
{ return this->_M_len == 0; }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/empty_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/empty_neg.cc
new file mode 100644
index 00000000000..59c87d007d8
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/empty_neg.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2017 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+void
+test01()
+{
+ std::string_view s;
+ s.empty(); // { dg-warning "ignoring return value" }
+}
diff --git a/libstdc++-v3/testsuite/24_iterators/range_access_cpp17_neg.cc b/libstdc++-v3/testsuite/24_iterators/range_access_cpp17_neg.cc
new file mode 100644
index 00000000000..12de34eb6e4
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/range_access_cpp17_neg.cc
@@ -0,0 +1,44 @@
+// Copyright (C) 2017 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <iterator>
+#include <initializer_list>
+
+void
+test01()
+{
+ struct A { bool empty() const { return true; } };
+ A a;
+ std::empty(a); // { dg-warning "ignoring return value" }
+}
+
+void
+test02()
+{
+ int a[2];
+ std::empty(a); // { dg-warning "ignoring return value" }
+}
+
+void
+test03()
+{
+ std::initializer_list<int> a{};
+ std::empty(a); // { dg-warning "ignoring return value" }
+}
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty_neg.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty_neg.cc
new file mode 100644
index 00000000000..7d38b494e9e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty_neg.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2017 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <filesystem>
+
+void
+test01()
+{
+ std::filesystem::path p;
+ p.empty(); // { dg-warning "ignoring return value" }
+}