Author: ericwf Date: Thu Feb 16 21:25:08 2017 New Revision: 295406 URL: http://llvm.org/viewvc/llvm-project?rev=295406&view=rev Log: [libcxx] Remove unexpected handlers in C++17
Summary: This patch implements [P0003R5](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0003r5.html) which removes exception specifications from C++17. The only changes to the library are removing `set_unexpected`, `get_unexpected`, `unexpected`, and `unexpected_handler`. These functions can be re-enabled in C++17 using `_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS`. @mclow.lists what do you think about removing stuff is this way? Reviewers: mclow.lists Reviewed By: mclow.lists Subscribers: mclow.lists, cfe-commits Differential Revision: https://reviews.llvm.org/D28172 Added: libcxx/trunk/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp libcxx/trunk/test/libcxx/depr/exception.unexpected/ libcxx/trunk/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp libcxx/trunk/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp Modified: libcxx/trunk/docs/UsingLibcxx.rst libcxx/trunk/include/__config libcxx/trunk/include/exception libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp libcxx/trunk/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp libcxx/trunk/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp libcxx/trunk/www/cxx1z_status.html Modified: libcxx/trunk/docs/UsingLibcxx.rst URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/UsingLibcxx.rst?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/docs/UsingLibcxx.rst (original) +++ libcxx/trunk/docs/UsingLibcxx.rst Thu Feb 16 21:25:08 2017 @@ -180,3 +180,13 @@ thread safety annotations. * 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. Modified: libcxx/trunk/include/__config URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/include/__config (original) +++ libcxx/trunk/include/__config Thu Feb 16 21:25:08 2017 @@ -1056,6 +1056,10 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit # 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 Modified: libcxx/trunk/include/exception URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/exception?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/include/exception (original) +++ libcxx/trunk/include/exception Thu Feb 16 21:25:08 2017 @@ -112,10 +112,14 @@ public: }; #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; Added: libcxx/trunk/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp?rev=295406&view=auto ============================================================================== --- libcxx/trunk/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp (added) +++ libcxx/trunk/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp Thu Feb 16 21:25:08 2017 @@ -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() { +} Added: libcxx/trunk/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp?rev=295406&view=auto ============================================================================== --- libcxx/trunk/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp (added) +++ libcxx/trunk/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp Thu Feb 16 21:25:08 2017 @@ -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); +} Added: libcxx/trunk/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp?rev=295406&view=auto ============================================================================== --- libcxx/trunk/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp (added) +++ libcxx/trunk/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp Thu Feb 16 21:25:08 2017 @@ -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); +} Added: libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp?rev=295406&view=auto ============================================================================== --- libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp (added) +++ libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp Thu Feb 16 21:25:08 2017 @@ -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); +} Added: libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp?rev=295406&view=auto ============================================================================== --- libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp (added) +++ libcxx/trunk/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp Thu Feb 16 21:25:08 2017 @@ -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'}} +} Modified: libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp (original) +++ libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp Thu Feb 16 21:25:08 2017 @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// REQUIRES: c++98 || c++03 || c++11 || c++14 + // test get_unexpected #include <exception> Modified: libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp (original) +++ libcxx/trunk/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp Thu Feb 16 21:25:08 2017 @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// REQUIRES: c++98 || c++03 || c++11 || c++14 + // test set_unexpected #include <exception> Modified: libcxx/trunk/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp (original) +++ libcxx/trunk/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp Thu Feb 16 21:25:08 2017 @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// REQUIRES: c++98 || c++03 || c++11 || c++14 + // test unexpected_handler #include <exception> Modified: libcxx/trunk/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp (original) +++ libcxx/trunk/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp Thu Feb 16 21:25:08 2017 @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// REQUIRES: c++98 || c++03 || c++11 || c++14 + // test unexpected #include <exception> Modified: libcxx/trunk/www/cxx1z_status.html URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=295406&r1=295405&r2=295406&view=diff ============================================================================== --- libcxx/trunk/www/cxx1z_status.html (original) +++ libcxx/trunk/www/cxx1z_status.html Thu Feb 16 21:25:08 2017 @@ -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> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits