From 2a1bfa98d1c2fc1528c1adcfb3a9d499c39118cd Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Fri, 17 Feb 2017 03:25:08 +0000 Subject: [PATCH] [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 llvm-svn: 295406 --- libcxx/docs/UsingLibcxx.rst | 10 +++++ libcxx/include/__config | 4 ++ libcxx/include/exception | 4 ++ .../enable_removed_cpp17_features.pass.cpp | 22 ++++++++++ .../get_unexpected.pass.cpp | 42 +++++++++++++++++++ .../set_unexpected.pass.cpp | 37 ++++++++++++++++ .../exception.unexpected/unexpected.pass.cpp | 28 +++++++++++++ .../unexpected_disabled_cpp17.fail.cpp | 23 ++++++++++ .../set.unexpected/get_unexpected.pass.cpp | 2 + .../set.unexpected/set_unexpected.pass.cpp | 2 + .../unexpected_handler.pass.cpp | 2 + .../unexpected/unexpected.pass.cpp | 2 + libcxx/www/cxx1z_status.html | 2 +- 13 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 libcxx/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp create mode 100644 libcxx/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp create mode 100644 libcxx/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp create mode 100644 libcxx/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp create mode 100644 libcxx/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp diff --git a/libcxx/docs/UsingLibcxx.rst b/libcxx/docs/UsingLibcxx.rst index 6d910ca6f308..9020a2c36013 100644 --- a/libcxx/docs/UsingLibcxx.rst +++ b/libcxx/docs/UsingLibcxx.rst @@ -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. diff --git a/libcxx/include/__config b/libcxx/include/__config index 3853916a0cb9..fd1dc8609e78 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1056,6 +1056,10 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( # 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 diff --git a/libcxx/include/exception b/libcxx/include/exception index db11c36d806d..8828709f8d5b 100644 --- a/libcxx/include/exception +++ b/libcxx/include/exception @@ -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; diff --git a/libcxx/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp b/libcxx/test/libcxx/depr/enable_removed_cpp17_features.pass.cpp new file mode 100644 index 000000000000..3962d536be34 --- /dev/null +++ b/libcxx/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() { +} diff --git a/libcxx/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp b/libcxx/test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp new file mode 100644 index 000000000000..55e23b9eda59 --- /dev/null +++ b/libcxx/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 +#include +#include + +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); +} diff --git a/libcxx/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp b/libcxx/test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp new file mode 100644 index 000000000000..c4915dd10063 --- /dev/null +++ b/libcxx/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 +#include +#include + +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); +} diff --git a/libcxx/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp b/libcxx/test/libcxx/depr/exception.unexpected/unexpected.pass.cpp new file mode 100644 index 000000000000..7a84b92ca98a --- /dev/null +++ b/libcxx/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 +#include +#include + +void fexit() +{ + std::exit(0); +} + +int main() +{ + std::set_unexpected(fexit); + std::unexpected(); + assert(false); +} diff --git a/libcxx/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp b/libcxx/test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp new file mode 100644 index 000000000000..2a2917625fe5 --- /dev/null +++ b/libcxx/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 + +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'}} +} diff --git a/libcxx/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp b/libcxx/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp index 02f9a81aa6dd..5c596da5a0bc 100644 --- a/libcxx/test/std/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp +++ b/libcxx/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 diff --git a/libcxx/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp b/libcxx/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp index ed02fa618e8e..9b9d726f7f3c 100644 --- a/libcxx/test/std/depr/exception.unexpected/set.unexpected/set_unexpected.pass.cpp +++ b/libcxx/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 diff --git a/libcxx/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp b/libcxx/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp index 5879529317ef..f6bc5bc5a68c 100644 --- a/libcxx/test/std/depr/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp +++ b/libcxx/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 diff --git a/libcxx/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp b/libcxx/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp index 03b484f7631a..92d4d38e272b 100644 --- a/libcxx/test/std/depr/exception.unexpected/unexpected/unexpected.pass.cpp +++ b/libcxx/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 diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index 918782480e8b..b378f73de431 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -122,7 +122,7 @@ p0393r3LWGMaking Variant Greater EqualOuluComplete4.0 P0394r4LWGHotel Parallelifornia: terminate() for Parallel Algorithms Exception HandlingOulu - P0003R5LWGRemoving Deprecated Exception Specifications from C++17Issaquah + P0003R5LWGRemoving Deprecated Exception Specifications from C++17IssaquahComplete5.0 P0067R5LWGElementary string conversions, revision 5Issaquah P0403R1LWGLiteral suffixes for basic_string_viewIssaquahComplete4.0 P0414R2LWGMerging shared_ptr changes from Library Fundamentals to C++17Issaquah