1717#include " google/cloud/terminate_handler.h"
1818#include < stdexcept>
1919
20- // This function is only needed if exceptions are enabled.
21- #ifdef GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
22- // TODO(#14152): Remove libC++ hack
23- // The `std::future_error::future_error(std::future_errc)` constructor is not
24- // guaranteed to exist until C++17. Fortunately, stdlibc++, MSVC are forgiving,
25- // and libc++ is forgiving until version 18.1.
26- #if GOOGLE_CLOUD_CPP_CPP_VERSION >= 201703L || _LIBCPP_VERSION < 180100
27-
28- namespace {
29- std::future_error MakeFutureErrorImpl (std::future_errc ec) {
30- return std::future_error (ec);
31- }
32- } // namespace
33-
34- #else
35- // We can probably tolerate this terrible hack (which depends on UB) until we
36- // require C++17.
37- namespace {
38- struct OhTheHorrors {};
39- } // namespace
40-
41- namespace std {
42- template <>
43- class promise <OhTheHorrors> {
44- public:
45- static auto MakeFutureError (std::future_errc ec) {
46- return std::future_error (std::make_error_code (ec));
47- }
48- };
49- } // namespace std
50-
51- namespace {
52- std::future_error MakeFutureErrorImpl (std::future_errc ec) {
53- return std::promise<OhTheHorrors>::MakeFutureError (ec);
54- }
55- } // namespace
56-
57- #endif
58- #endif // GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
59-
6020namespace google {
6121namespace cloud {
6222GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
@@ -65,7 +25,7 @@ namespace internal {
6525[[noreturn]] void ThrowFutureError (std::future_errc ec, char const * msg) {
6626#ifdef GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
6727 (void )msg; // disable unused argument warning.
68- throw MakeFutureErrorImpl (ec);
28+ throw std::future_error (ec);
6929#else
7030 std::string full_msg = " future_error[" ;
7131 full_msg += std::make_error_code (ec).message ();
@@ -87,7 +47,7 @@ namespace internal {
8747
8848std::exception_ptr MakeFutureError (std::future_errc ec) {
8949#ifdef GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
90- return std::make_exception_ptr (MakeFutureErrorImpl (ec));
50+ return std::make_exception_ptr (std::future_error (ec));
9151#else
9252 (void )ec;
9353 // We cannot create a valid `std::exception_ptr` in this case. It does not
0 commit comments