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. 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: 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: 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: 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 +#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); +} 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 +#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); +} 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 +#include +#include + +void fexit() +{ + std::exit(0); +} + +int main() +{ + std::set_unexpected(fexit); + std::unexpected(); + assert(false); +} 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 + +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/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 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 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 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 Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ 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