diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2017-11-24 00:00:46 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2017-11-24 00:00:46 +0000 |
commit | a8541d9021fa0424397a63e5d7ef3b2ef0ea7c47 (patch) | |
tree | 869e4a4b94ada09249de3fa75a23531b682ea3cc /libstdc++-v3 | |
parent | 117e6b50b6879c11589bc8287199652a626594d1 (diff) | |
download | gcc-a8541d9021fa0424397a63e5d7ef3b2ef0ea7c47.zip gcc-a8541d9021fa0424397a63e5d7ef3b2ef0ea7c47.tar.gz gcc-a8541d9021fa0424397a63e5d7ef3b2ef0ea7c47.tar.bz2 |
Add [[nodiscard]] attribute to std::launder
* libsupc++/new (launder): Add nodiscard attribute.
* testsuite/18_support/launder/nodiscard.cc: New test.
From-SVN: r255127
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 3 | ||||
-rw-r--r-- | libstdc++-v3/libsupc++/new | 4 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/18_support/launder/nodiscard.cc | 29 |
3 files changed, 34 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3b2dad0..d098ccc 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,8 @@ 2017-11-23 Jonathan Wakely <jwakely@redhat.com> + * libsupc++/new (launder): Add nodiscard attribute. + * testsuite/18_support/launder/nodiscard.cc: New test. + * 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. diff --git a/libstdc++-v3/libsupc++/new b/libstdc++-v3/libsupc++/new index 795b33c..0e408b1 100644 --- a/libstdc++-v3/libsupc++/new +++ b/libstdc++-v3/libsupc++/new @@ -176,7 +176,7 @@ inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { } //@} } // extern "C++" -#if __cplusplus > 201402L +#if __cplusplus >= 201703L #if __GNUC__ >= 7 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1 #elif defined __has_builtin @@ -192,7 +192,7 @@ namespace std #define __cpp_lib_launder 201606 /// Pointer optimization barrier [ptr.launder] template<typename _Tp> - constexpr _Tp* + [[nodiscard]] constexpr _Tp* launder(_Tp* __p) noexcept { return __builtin_launder(__p); } diff --git a/libstdc++-v3/testsuite/18_support/launder/nodiscard.cc b/libstdc++-v3/testsuite/18_support/launder/nodiscard.cc new file mode 100644 index 0000000..1741465 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/launder/nodiscard.cc @@ -0,0 +1,29 @@ +// 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 <new> + +struct A { const int i; }; + +void +test01(A* a) +{ + std::launder(a); // { dg-warning "ignoring return value" } +} |