[libcxx] r294165 - Implement LWG 2773 - std::ignore should be constexpr.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 5 17:25:32 PST 2017


Author: ericwf
Date: Sun Feb  5 19:25:31 2017
New Revision: 294165

URL: http://llvm.org/viewvc/llvm-project?rev=294165&view=rev
Log:
Implement LWG 2773 - std::ignore should be constexpr.

In addition to the PR for LWG 2773 this patch also ensures
that each of std::ignores constructors or assignment operators
are constexpr.

Added:
    libcxx/trunk/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
Modified:
    libcxx/trunk/include/tuple
    libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
    libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/tuple?rev=294165&r1=294164&r2=294165&view=diff
==============================================================================
--- libcxx/trunk/include/tuple (original)
+++ libcxx/trunk/include/tuple Sun Feb  5 19:25:31 2017
@@ -1064,11 +1064,13 @@ template <class _Up>
 struct __ignore_t
 {
     template <class _Tp>
-        _LIBCPP_INLINE_VISIBILITY
-        const __ignore_t& operator=(_Tp&&) const {return *this;}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    const __ignore_t& operator=(_Tp&&) const {return *this;}
 };
 
-namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
+namespace {
+  constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
+}
 
 template <class _Tp>
 struct __make_tuple_return_impl

Added: libcxx/trunk/test/std/utilities/tuple/tuple.general/ignore.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.general/ignore.pass.cpp?rev=294165&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/tuple/tuple.general/ignore.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/tuple/tuple.general/ignore.pass.cpp Sun Feb  5 19:25:31 2017
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <tuple>
+
+// constexpr unspecified ignore;
+
+// UNSUPPORTED: c++98, c++03
+
+#include <tuple>
+#include <cassert>
+
+#include "test_macros.h"
+
+constexpr bool test_ignore_constexpr()
+{
+#if TEST_STD_VER > 11
+    { // Test that std::ignore provides constexpr converting assignment.
+        auto& res = (std::ignore = 42);
+        assert(&res == &std::ignore);
+    }
+    { // Test that std::ignore provides constexpr copy/move constructors
+        auto copy = std::ignore;
+        auto moved = std::move(copy);
+        ((void)moved);
+    }
+    { // Test that std::ignore provides constexpr copy/move assignment
+        auto copy = std::ignore;
+        copy = std::ignore;
+        auto moved = std::ignore;
+        moved = std::move(copy);
+    }
+#endif
+    return true;
+}
+
+int main() {
+    {
+        constexpr auto& ignore_v = std::ignore;
+        ((void)ignore_v);
+    }
+    {
+        static_assert(test_ignore_constexpr(), "");
+    }
+#if defined(_LIBCPP_VERSION)
+    {
+        static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
+    }
+#endif
+}

Modified: libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp?rev=294165&r1=294164&r2=294165&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp Sun Feb  5 19:25:31 2017
@@ -22,6 +22,24 @@
 
 #include "test_macros.h"
 
+#if TEST_STD_VER > 11
+constexpr bool test_tie_constexpr() {
+    {
+        int i = 42;
+        double f = 1.1;
+        using ExpectT = std::tuple<int&, decltype(std::ignore)&, double&>;
+        auto res = std::tie(i, std::ignore, f);
+        static_assert(std::is_same<ExpectT, decltype(res)>::value, "");
+        assert(&std::get<0>(res) == &i);
+        assert(&std::get<1>(res) == &std::ignore);
+        assert(&std::get<2>(res) == &f);
+        // FIXME: If/when tuple gets constexpr assignment
+        //res = std::make_tuple(101, nullptr, -1.0);
+    }
+    return true;
+}
+#endif
+
 int main()
 {
     {
@@ -39,5 +57,8 @@ int main()
         static_assert ( std::get<0>(t) == 42, "" );
         static_assert ( std::get<1>(t) == 1.1, "" );
     }
+    {
+        static_assert(test_tie_constexpr(), "");
+    }
 #endif
 }

Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=294165&r1=294164&r2=294165&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Sun Feb  5 19:25:31 2017
@@ -407,7 +407,7 @@
 	<tr><td><a href="http://wg21.link/LWG2767">2767</a></td><td>not_fn call_wrapper can form invalid types</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://wg21.link/LWG2769">2769</a></td><td>Redundant const in the return type of any_cast(const any&)</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://wg21.link/LWG2771">2771</a></td><td>Broken Effects of some basic_string::compare functions in terms of basic_string_view</td><td>Issaquah</td><td>Complete</td></tr>
-	<tr><td><a href="http://wg21.link/LWG2773">2773</a></td><td>Making std::ignore constexpr</td><td>Issaquah</td><td></td></tr>
+	<tr><td><a href="http://wg21.link/LWG2773">2773</a></td><td>Making std::ignore constexpr</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://wg21.link/LWG2777">2777</a></td><td>basic_string_view::copy should use char_traits::copy</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://wg21.link/LWG2778">2778</a></td><td>basic_string_view is missing constexpr</td><td>Issaquah</td><td>Complete</td></tr>
 




More information about the cfe-commits mailing list