On 23/11/17 22:40 +0000, Jonathan Wakely wrote:
C++17 added the [[nodiscard]] attribute, similar to GCC's
warn_unused_result. The C++2a draft requires it to be used in several
places. This patch adds it where required on components which are new
to C++17, which are still experimental and so I'm changing them in
stage 3.

I missed one of the C++17 pieces that should have [[nodiscard]].

Tested powerpc64le-linux, committed to trunk.


commit 65c20af6ec193916e390462ccfbd8e8e6b54ba8c
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Nov 23 22:51:31 2017 +0000

    Add [[nodiscard]] attribute to std::launder
    
            * libsupc++/new (launder): Add nodiscard attribute.
            * testsuite/18_support/launder/nodiscard.cc: New test.

diff --git a/libstdc++-v3/libsupc++/new b/libstdc++-v3/libsupc++/new
index 795b33c4e6a..0e408b1019c 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 00000000000..1741465abed
--- /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" }
+}

Reply via email to