[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
This commit is contained in:
Eric Fiselier 2017-02-17 03:25:08 +00:00
parent 571c05a550
commit 2a1bfa98d1
13 changed files with 179 additions and 1 deletions

View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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() {
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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'}}
}

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// REQUIRES: c++98 || c++03 || c++11 || c++14
// test get_unexpected
#include <exception>

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// REQUIRES: c++98 || c++03 || c++11 || c++14
// test set_unexpected
#include <exception>

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// REQUIRES: c++98 || c++03 || c++11 || c++14
// test unexpected_handler
#include <exception>

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// REQUIRES: c++98 || c++03 || c++11 || c++14
// test unexpected
#include <exception>

View File

@ -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>