EricWF updated this revision to Diff 88843.
EricWF added a comment.

- Update so that it merges with master.

- add `_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES` macro for re-enabling all removed 
C++17 features.


https://reviews.llvm.org/D28172

Files:
  docs/UsingLibcxx.rst
  include/__config
  include/exception
  test/libcxx/depr/enable_removed_cpp17_features.pass.cpp
  test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp
  test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp
  test/libcxx/depr/exception.unexpected/unexpected.pass.cpp
  test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp
  test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp
  test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp
  
test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp
  test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===================================================================
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -122,7 +122,7 @@
 	<tr><td><a href="http://wg21.link/p0393r3";>p0393r3</a></td><td>LWG</td><td>Making Variant Greater Equal</td><td>Oulu</td><td>Complete</td><td>4.0</td></tr>
 	<tr><td><a href="http://wg21.link/P0394r4";>P0394r4</a></td><td>LWG</td><td>Hotel Parallelifornia: terminate() for Parallel Algorithms Exception Handling</td><td>Oulu</td><td></td><td></td></tr>
   	<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>
-	<tr><td><a href="http://wg21.link/P0003R5";>P0003R5</a></td><td>LWG</td><td>Removing Deprecated Exception Specifications from C++17</td><td>Issaquah</td><td></td><td></td></tr>
+	<tr><td><a href="http://wg21.link/P0003R5";>P0003R5</a></td><td>LWG</td><td>Removing Deprecated Exception Specifications from C++17</td><td>Issaquah</td><td>Complete</td><td>5.0</td></tr>
 	<tr><td><a href="http://wg21.link/P0067R5";>P0067R5</a></td><td>LWG</td><td>Elementary string conversions, revision 5</td><td>Issaquah</td><td></td><td></td></tr>
 	<tr><td><a href="http://wg21.link/P0403R1";>P0403R1</a></td><td>LWG</td><td>Literal suffixes for <tt>basic_string_view</tt></td><td>Issaquah</td><td>Complete</td><td>4.0</td></tr>
 	<tr><td><a href="http://wg21.link/P0414R2";>P0414R2</a></td><td>LWG</td><td>Merging shared_ptr changes from Library Fundamentals to C++17</td><td>Issaquah</td><td></td><td></td></tr>
Index: test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp
===================================================================
--- test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp
+++ test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp
@@ -7,6 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// REQUIRES: c++98 || c++03 || c++11 || c++14
+
 // test unexpected
 
 #include <exception>
Index: test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp
===================================================================
--- test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp
+++ test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp
@@ -7,6 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// REQUIRES: c++98 || c++03 || c++11 || c++14
+
 // test unexpected_handler
 
 #include <exception>
Index: test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp
===================================================================
--- test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp
+++ test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp
@@ -7,6 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// REQUIRES: c++98 || c++03 || c++11 || c++14
+
 // test set_unexpected
 
 #include <exception>
Index: test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp
===================================================================
--- test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp
+++ test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp
@@ -7,6 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// REQUIRES: c++98 || c++03 || c++11 || c++14
+
 // test get_unexpected
 
 #include <exception>
Index: test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp
===================================================================
--- /dev/null
+++ test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// test unexpected
+
+#include <exception>
+
+void f() {}
+
+int main() {
+  using T = std::unexpected_handler; // expected-error {{no type named 'unexpected_handler' in namespace 'std'}}
+  std::unexpected(); // expected-error {{no member named 'unexpected' in namespace 'std'}}
+  std::get_unexpected(); // expected-error {{no member named 'get_unexpected' in namespace 'std'}}
+  std::set_unexpected(f); // expected-error {{no type named 'set_unexpected' in namespace 'std'}}
+}
Index: test/libcxx/depr/exception.unexpected/unexpected.pass.cpp
===================================================================
--- /dev/null
+++ test/libcxx/depr/exception.unexpected/unexpected.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// test unexpected
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#include <exception>
+#include <cstdlib>
+#include <cassert>
+
+void fexit()
+{
+    std::exit(0);
+}
+
+int main()
+{
+    std::set_unexpected(fexit);
+    std::unexpected();
+    assert(false);
+}
Index: test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp
===================================================================
--- /dev/null
+++ test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// test set_unexpected
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#include <exception>
+#include <cassert>
+#include <cstdlib>
+
+void f1() {}
+void f2() {}
+
+void f3()
+{
+    std::exit(0);
+}
+
+int main()
+{
+    std::unexpected_handler old = std::set_unexpected(f1);
+    // verify there is a previous unexpected handler
+    assert(old);
+    // verify f1 was replace with f2
+    assert(std::set_unexpected(f2) == f1);
+    // verify calling original unexpected handler calls terminate
+    std::set_terminate(f3);
+    (*old)();
+    assert(0);
+}
Index: test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp
===================================================================
--- /dev/null
+++ test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// test get_unexpected
+
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#include <exception>
+#include <cassert>
+#include <cstdlib>
+
+void f1() {}
+void f2() {}
+
+void f3()
+{
+    std::exit(0);
+}
+
+int main()
+{
+
+    std::unexpected_handler old = std::get_unexpected();
+    // verify there is a previous unexpected handler
+    assert(old);
+    std::set_unexpected(f1);
+    assert(std::get_unexpected() == f1);
+    // verify f1 was replace with f2
+    std::set_unexpected(f2);
+    assert(std::get_unexpected() == f2);
+    // verify calling original unexpected handler calls terminate
+    std::set_terminate(f3);
+    (*old)();
+    assert(0);
+}
Index: test/libcxx/depr/enable_removed_cpp17_features.pass.cpp
===================================================================
--- /dev/null
+++ test/libcxx/depr/enable_removed_cpp17_features.pass.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that defining _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES correctly defines
+// _LIBCPP_ENABLE_CXX17_REMOVED_FOO for each individual component macro.
+
+// MODULES_DEFINES: _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
+#define _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
+#include <__config>
+
+#ifndef _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#error _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS must be defined
+#endif
+
+int main() {
+}
Index: include/exception
===================================================================
--- include/exception
+++ include/exception
@@ -112,10 +112,14 @@
 };
 #endif // !_LIBCPP_ABI_MICROSOFT
 
+#if _LIBCPP_STD_VER <= 14 \
+    || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \
+    || defined(_LIBCPP_BUILDING_LIBRARY)
 typedef void (*unexpected_handler)();
 _LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT;
 _LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT;
 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected();
+#endif
 
 typedef void (*terminate_handler)();
 _LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -1056,6 +1056,10 @@
 # define _LIBCPP_DECLSPEC_EMPTY_BASES
 #endif
 
+#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
+# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
+#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
+
 #endif // __cplusplus
 
 #endif // _LIBCPP_CONFIG
Index: docs/UsingLibcxx.rst
===================================================================
--- docs/UsingLibcxx.rst
+++ docs/UsingLibcxx.rst
@@ -180,3 +180,13 @@
     * Giving `set`, `map`, `multiset`, `multimap` a comparator which is not
       const callable.
 
+C++17 Specific Configuration Macros
+-----------------------------------
+**_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES**:
+  This macro is used to re-enable all the features removed in C++17. The effect
+  is equivalent to manually defining each macro listed below.
+
+**_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS**:
+  This macro is used to re-enable the `set_unexpected`, `get_unexpected`, and
+  `unexpected` functions, which were removed in C++17. Unless this macro is
+  define those names will not be available in C++17.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to