2 * Copyright 2017-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * Author: Eric Niebler <eniebler@fb.com>
28 #include <type_traits>
32 #include <folly/Assume.h>
33 #include <folly/CPortability.h>
34 #include <folly/Demangle.h>
35 #include <folly/ExceptionString.h>
36 #include <folly/FBString.h>
37 #include <folly/Portability.h>
38 #include <folly/Traits.h>
41 #pragma GCC diagnostic push
42 #pragma GCC diagnostic ignored "-Wpragmas"
43 #pragma GCC diagnostic ignored "-Wpotentially-evaluated-expression"
44 // GCC gets confused about lambda scopes and issues shadow-local warnings for
45 // parameters in totally different functions.
46 FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS
49 #define FOLLY_EXCEPTION_WRAPPER_H_INCLUDED
53 #define FOLLY_REQUIRES_DEF(...) \
54 _t<std::enable_if<static_cast<bool>(__VA_ARGS__), long>>
56 #define FOLLY_REQUIRES(...) FOLLY_REQUIRES_DEF(__VA_ARGS__) = __LINE__
58 namespace exception_wrapper_detail {
60 template <template <class> class T, class... As>
61 using AllOf = StrictConjunction<T<As>...>;
63 template <bool If, class T>
64 using AddConstIf = _t<std::conditional<If, const T, T>>;
66 template <class Fn, class A>
67 FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN
68 auto fold(Fn&&, A&& a) {
69 return static_cast<A&&>(a);
72 template <class Fn, class A, class B, class... Bs>
73 FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN
74 auto fold(Fn&& fn, A&& a, B&& b, Bs&&... bs) {
76 // This looks like a use of fn after a move of fn, but in reality, this is
77 // just a cast and not a move. That's because regardless of which fold
78 // overload is selected, fn gets bound to a &&. Had fold taken fn by value
79 // there would indeed be a problem here.
80 static_cast<Fn&&>(fn),
81 static_cast<Fn&&>(fn)(static_cast<A&&>(a), static_cast<B&&>(b)),
82 static_cast<Bs&&>(bs)...);
85 } // namespace exception_wrapper_detail
87 //! Throwing exceptions can be a convenient way to handle errors. Storing
88 //! exceptions in an `exception_ptr` makes it easy to handle exceptions in a
89 //! different thread or at a later time. `exception_ptr` can also be used in a
90 //! very generic result/exception wrapper.
92 //! However, there are some issues with throwing exceptions and
93 //! `std::exception_ptr`. These issues revolve around `throw` being expensive,
94 //! particularly in a multithreaded environment (see
95 //! ExceptionWrapperBenchmark.cpp).
97 //! Imagine we have a library that has an API which returns a result/exception
98 //! wrapper. Let's consider some approaches for implementing this wrapper.
99 //! First, we could store a `std::exception`. This approach loses the derived
100 //! exception type, which can make exception handling more difficult for users
101 //! that prefer rethrowing the exception. We could use a `folly::dynamic` for
102 //! every possible type of exception. This is not very flexible - adding new
103 //! types of exceptions requires a change to the result/exception wrapper. We
104 //! could use an `exception_ptr`. However, constructing an `exception_ptr` as
105 //! well as accessing the error requires a call to throw. That means that there
106 //! will be two calls to throw in order to process the exception. For
107 //! performance sensitive applications, this may be unacceptable.
109 //! `exception_wrapper` is designed to handle exception management for both
110 //! convenience and high performance use cases. `make_exception_wrapper` is
111 //! templated on derived type, allowing us to rethrow the exception properly for
112 //! users that prefer convenience. These explicitly named exception types can
113 //! therefore be handled without any peformance penalty. `exception_wrapper` is
114 //! also flexible enough to accept any type. If a caught exception is not of an
115 //! explicitly named type, then `std::exception_ptr` is used to preserve the
116 //! exception state. For performance sensitive applications, the accessor
117 //! methods can test or extract a pointer to a specific exception type with very
120 //! \par Example usage:
123 //! exception_wrapper globalExceptionWrapper;
126 //! void doSomethingCrazy() {
127 //! int rc = doSomethingCrazyWithLameReturnCodes();
128 //! if (rc == NAILED_IT) {
129 //! globalExceptionWrapper = exception_wrapper();
130 //! } else if (rc == FACE_PLANT) {
131 //! globalExceptionWrapper = make_exception_wrapper<FacePlantException>();
132 //! } else if (rc == FAIL_WHALE) {
133 //! globalExceptionWrapper = make_exception_wrapper<FailWhaleException>();
137 //! // Thread2: Exceptions are ok!
138 //! void processResult() {
140 //! globalExceptionWrapper.throw_exception();
141 //! } catch (const FacePlantException& e) {
142 //! LOG(ERROR) << "FACEPLANT!";
143 //! } catch (const FailWhaleException& e) {
144 //! LOG(ERROR) << "FAILWHALE!";
148 //! // Thread2: Exceptions are bad!
149 //! void processResult() {
150 //! globalExceptionWrapper.handle(
151 //! [&](FacePlantException& faceplant) {
152 //! LOG(ERROR) << "FACEPLANT";
154 //! [&](FailWhaleException& failwhale) {
155 //! LOG(ERROR) << "FAILWHALE!";
158 //! LOG(FATAL) << "Unrecognized exception";
162 class exception_wrapper final {
164 struct AnyException : std::exception {
165 std::type_info const* typeinfo_;
167 /* implicit */ AnyException(T&& t) noexcept : typeinfo_(&typeid(t)) {}
173 using arg_type = _t<arg_type_<Fn>>;
175 // exception_wrapper is implemented as a simple variant over four
176 // different representations:
177 // 0. Empty, no exception.
178 // 1. An small object stored in-situ.
179 // 2. A larger object stored on the heap and referenced with a
181 // 3. A std::exception_ptr, together with either:
182 // a. A pointer to the referenced std::exception object, or
183 // b. A pointer to a std::type_info object for the referenced exception,
184 // or for an unspecified type if the type is unknown.
185 // This is accomplished with the help of a union and a pointer to a hand-
186 // rolled virtual table. This virtual table contains pointers to functions
187 // that know which field of the union is active and do the proper action.
188 // The class invariant ensures that the vtable ptr and the union stay in sync.
190 void (*copy_)(exception_wrapper const*, exception_wrapper*);
191 void (*move_)(exception_wrapper*, exception_wrapper*);
192 void (*delete_)(exception_wrapper*);
193 void (*throw_)(exception_wrapper const*);
194 std::type_info const* (*type_)(exception_wrapper const*);
195 std::exception const* (*get_exception_)(exception_wrapper const*);
196 exception_wrapper (*get_exception_ptr_)(exception_wrapper const*);
199 [[noreturn]] static void onNoExceptionError();
201 template <class Ret, class... Args>
202 static Ret noop_(Args...);
204 static std::type_info const* uninit_type_(exception_wrapper const*);
206 static VTable const uninit_;
209 using IsStdException = std::is_base_of<std::exception, _t<std::decay<Ex>>>;
210 template <bool B, class T>
211 using AddConstIf = exception_wrapper_detail::AddConstIf<B, T>;
212 template <class CatchFn>
214 std::is_same<arg_type<_t<std::decay<CatchFn>>>, AnyException>;
218 // Sadly, with the gcc-4.9 platform, std::logic_error and std::runtime_error
219 // do not fit here. They also don't have noexcept copy-ctors, so the internal
220 // storage wouldn't be used anyway. For the gcc-5 platform, both logic_error
221 // and runtime_error can be safely stored internally.
224 _t<std::aligned_storage<2 * sizeof(void*), alignof(std::exception)>>;
227 Buffer() : buff_{} {}
229 template <class Ex, typename... As>
230 Buffer(in_place_type_t<Ex>, As&&... as_);
234 Ex const& as() const noexcept;
237 enum class Placement { kInSitu, kOnHeap };
239 using PlacementOf = std::integral_constant<
241 sizeof(T) <= sizeof(Buffer::Storage) &&
242 alignof(T) <= alignof(Buffer::Storage) &&
243 noexcept(T(std::declval<T&&>()))
245 : Placement::kOnHeap>;
247 using InSituTag = std::integral_constant<Placement, Placement::kInSitu>;
248 using OnHeapTag = std::integral_constant<Placement, Placement::kOnHeap>;
250 static std::exception const* as_exception_or_null_(std::exception const& ex);
251 static std::exception const* as_exception_or_null_(AnyException);
253 struct ExceptionPtr {
254 std::exception_ptr ptr_;
255 std::uintptr_t exception_or_type_; // odd for type_info
257 1 < alignof(std::exception) && 1 < alignof(std::type_info),
258 "Surprise! std::exception and std::type_info don't have alignment "
259 "greater than one. as_int_ below will not work!");
261 static std::uintptr_t as_int_(
262 std::exception_ptr const& ptr,
263 std::exception const& e);
264 static std::uintptr_t as_int_(
265 std::exception_ptr const& ptr,
267 bool has_exception_() const;
268 std::exception const* as_exception_() const;
269 std::type_info const* as_type_() const;
270 static void copy_(exception_wrapper const* from, exception_wrapper* to);
271 static void move_(exception_wrapper* from, exception_wrapper* to);
272 static void delete_(exception_wrapper* that);
273 [[noreturn]] static void throw_(exception_wrapper const* that);
274 static std::type_info const* type_(exception_wrapper const* that);
275 static std::exception const* get_exception_(exception_wrapper const* that);
276 static exception_wrapper get_exception_ptr_(exception_wrapper const* that);
277 static VTable const ops_;
282 static void copy_(exception_wrapper const* from, exception_wrapper* to);
283 static void move_(exception_wrapper* from, exception_wrapper* to);
284 static void delete_(exception_wrapper* that);
285 [[noreturn]] static void throw_(exception_wrapper const* that);
286 static std::type_info const* type_(exception_wrapper const*);
287 static std::exception const* get_exception_(exception_wrapper const* that);
288 static exception_wrapper get_exception_ptr_(exception_wrapper const* that);
289 static constexpr VTable const ops_{copy_,
300 std::type_info const* info_;
302 explicit Base(std::type_info const& info) : info_(&info) {}
304 virtual void throw_() const = 0;
305 virtual std::exception const* get_exception_() const noexcept = 0;
306 virtual exception_wrapper get_exception_ptr_() const noexcept = 0;
309 struct Impl final : public Base {
312 template <typename... As>
313 explicit Impl(As&&... as)
314 : Base{typeid(Ex)}, ex_(std::forward<As>(as)...) {}
315 [[noreturn]] void throw_() const override;
316 std::exception const* get_exception_() const noexcept override;
317 exception_wrapper get_exception_ptr_() const noexcept override;
319 std::shared_ptr<Base> ptr_;
321 static void copy_(exception_wrapper const* from, exception_wrapper* to);
322 static void move_(exception_wrapper* from, exception_wrapper* to);
323 static void delete_(exception_wrapper* that);
324 [[noreturn]] static void throw_(exception_wrapper const* that);
325 static std::type_info const* type_(exception_wrapper const* that);
326 static std::exception const* get_exception_(exception_wrapper const* that);
327 static exception_wrapper get_exception_ptr_(exception_wrapper const* that);
328 static VTable const ops_;
336 VTable const* vptr_{&uninit_};
338 template <class Ex, typename... As>
339 exception_wrapper(OnHeapTag, in_place_type_t<Ex>, As&&... as);
341 template <class Ex, typename... As>
342 exception_wrapper(InSituTag, in_place_type_t<Ex>, As&&... as);
345 struct IsRegularExceptionType
347 std::is_copy_constructible<T>,
348 Negation<std::is_base_of<exception_wrapper, T>>,
349 Negation<std::is_abstract<T>>> {};
351 template <class CatchFn, bool IsConst = false>
352 struct ExceptionTypeOf;
354 template <bool IsConst>
357 template <bool IsConst>
358 struct HandleStdExceptReduce;
360 template <class This, class... CatchFns>
361 static void handle_(std::false_type, This& this_, CatchFns&... fns);
363 template <class This, class... CatchFns>
364 static void handle_(std::true_type, This& this_, CatchFns&... fns);
366 template <class Ex, class This, class Fn>
367 static bool with_exception_(This& this_, Fn fn_);
370 //! Default-constructs an empty `exception_wrapper`
371 //! \post `type() == none()`
372 exception_wrapper() noexcept {}
374 //! Move-constructs an `exception_wrapper`
375 //! \post `*this` contains the value of `that` prior to the move
376 //! \post `that.type() == none()`
377 exception_wrapper(exception_wrapper&& that) noexcept;
379 //! Copy-constructs an `exception_wrapper`
380 //! \post `*this` contains a copy of `that`, and `that` is unmodified
381 //! \post `type() == that.type()`
382 exception_wrapper(exception_wrapper const& that);
384 //! Move-assigns an `exception_wrapper`
385 //! \pre `this != &that`
386 //! \post `*this` contains the value of `that` prior to the move
387 //! \post `that.type() == none()`
388 exception_wrapper& operator=(exception_wrapper&& that) noexcept;
390 //! Copy-assigns an `exception_wrapper`
391 //! \post `*this` contains a copy of `that`, and `that` is unmodified
392 //! \post `type() == that.type()`
393 exception_wrapper& operator=(exception_wrapper const& that);
395 ~exception_wrapper();
397 //! \pre `ptr` is empty, or it holds a reference to an exception that is not
398 //! derived from `std::exception`.
399 //! \post `!ptr || bool(*this)`
400 //! \post `hasThrownException() == true`
401 //! \post `type() == unknown()`
402 explicit exception_wrapper(std::exception_ptr ptr) noexcept;
404 //! \pre `ptr` holds a reference to `ex`.
405 //! \post `hasThrownException() == true`
406 //! \post `bool(*this)`
407 //! \post `type() == typeid(ex)`
409 exception_wrapper(std::exception_ptr ptr, Ex& ex);
411 //! \pre `typeid(ex) == typeid(typename decay<Ex>::type)`
412 //! \post `bool(*this)`
413 //! \post `hasThrownException() == false`
414 //! \post `type() == typeid(ex)`
415 //! \note Exceptions of types derived from `std::exception` can be implicitly
416 //! converted to an `exception_wrapper`.
419 class Ex_ = _t<std::decay<Ex>>,
421 Conjunction<IsStdException<Ex_>, IsRegularExceptionType<Ex_>>::value)>
422 /* implicit */ exception_wrapper(Ex&& ex);
424 //! \pre `typeid(ex) == typeid(typename decay<Ex>::type)`
425 //! \post `bool(*this)`
426 //! \post `hasThrownException() == false`
427 //! \post `type() == typeid(ex)`
428 //! \note Exceptions of types not derived from `std::exception` can still be
429 //! used to construct an `exception_wrapper`, but you must specify
430 //! `folly::in_place` as the first parameter.
433 class Ex_ = _t<std::decay<Ex>>,
434 FOLLY_REQUIRES(IsRegularExceptionType<Ex_>::value)>
435 exception_wrapper(in_place_t, Ex&& ex);
440 FOLLY_REQUIRES(IsRegularExceptionType<Ex>::value)>
441 exception_wrapper(in_place_type_t<Ex>, As&&... as);
443 //! Swaps the value of `*this` with the value of `that`
444 void swap(exception_wrapper& that) noexcept;
446 //! \return `true` if `*this` is not holding an exception.
447 explicit operator bool() const noexcept;
449 //! \return `!bool(*this)`
450 bool operator!() const noexcept;
452 //! Make this `exception_wrapper` empty
456 //! \return `true` if this `exception_wrapper` holds a reference to an
457 //! exception that was thrown (i.e., if it was constructed with
458 //! a `std::exception_ptr`, or if `to_exception_ptr()` was called on a
459 //! (non-const) reference to `*this`).
460 bool has_exception_ptr() const noexcept;
462 //! \return a pointer to the `std::exception` held by `*this`, if it holds
463 //! one; otherwise, returns `nullptr`.
464 //! \note This function does not mutate the `exception_wrapper` object.
465 //! \note This function never causes an exception to be thrown.
466 std::exception* get_exception() noexcept;
468 std::exception const* get_exception() const noexcept;
470 //! \returns a pointer to the `Ex` held by `*this`, if it holds an object
471 //! whose type `From` permits `std::is_convertible<From*, Ex*>`;
472 //! otherwise, returns `nullptr`.
473 //! \note This function does not mutate the `exception_wrapper` object.
474 //! \note This function may cause an exception to be thrown and immediately
475 //! caught internally, affecting runtime performance.
476 template <typename Ex>
477 Ex* get_exception() noexcept;
479 template <typename Ex>
480 Ex const* get_exception() const noexcept;
482 //! \return A `std::exception_ptr` that references either the exception held
483 //! by `*this`, or a copy of same.
484 //! \note This function may need to throw an exception to complete the action.
485 //! \note The non-const overload of this function mutates `*this` to cache the
486 //! computed `std::exception_ptr`; that is, this function may cause
487 //! `has_exception_ptr()` to change from `false` to `true`.
488 std::exception_ptr const& to_exception_ptr() noexcept;
490 std::exception_ptr to_exception_ptr() const noexcept;
492 //! \return the `typeid` of an unspecified type used by
493 //! `exception_wrapper::type()` to denote an empty `exception_wrapper`.
494 static std::type_info const& none() noexcept;
495 //! \return the `typeid` of an unspecified type used by
496 //! `exception_wrapper::type()` to denote an `exception_wrapper` that
497 //! holds an exception of unknown type.
498 static std::type_info const& unknown() noexcept;
500 //! Returns the `typeid` of the wrapped exception object. If there is no
501 //! wrapped exception object, returns `exception_wrapper::none()`. If
502 //! this instance wraps an exception of unknown type not derived from
503 //! `std::exception`, returns `exception_wrapper::unknown()`.
504 std::type_info const& type() const noexcept;
506 //! \return If `get_exception() != nullptr`, `class_name() + ": " +
507 //! get_exception()->what()`; otherwise, `class_name()`.
508 folly::fbstring what() const;
510 //! \return If `!*this`, the empty string; otherwise, if
511 //! `type() == unknown()`, the string `"<unknown exception>"`; otherwise,
512 //! the result of `type().name()` after demangling.
513 folly::fbstring class_name() const;
515 //! \tparam Ex The expression type to check for compatibility with.
516 //! \return `true` if and only if `*this` wraps an exception that would be
517 //! caught with a `catch(Ex const&)` clause.
518 //! \note If `*this` is empty, this function returns `false`.
520 bool is_compatible_with() const noexcept;
522 //! \pre `bool(*this)`
523 //! Throws the wrapped expression.
524 [[noreturn]] void throw_exception() const;
526 //! Call `fn` with the wrapped exception (if any), if `fn` can accept it.
529 //! exception_wrapper ew{std::runtime_error("goodbye cruel world")};
531 //! assert( ew.with_exception([](std::runtime_error& e){/*...*/}) );
533 //! assert( !ew.with_exception([](int& e){/*...*/}) );
535 //! assert( !exception_wrapper{}.with_exception([](int& e){/*...*/}) );
537 //! \tparam Ex Optionally, the type of the exception that `fn` accepts.
538 //! \tparam Fn The type of a monomophic function object.
539 //! \param fn A function object to call with the wrapped exception
540 //! \return `true` if and only if `fn` was called.
541 //! \note Optionally, you may explicitly specify the type of the exception
542 //! that `fn` expects, as in
544 //! ew.with_exception<std::runtime_error>([](auto&& e) { /*...*/; });
546 //! \note The handler may or may not be invoked with an active exception.
547 //! **Do not try to rethrow the exception with `throw;` from within your
548 //! handler -- that is, a throw expression with no operand.** This may
549 //! cause your process to terminate. (It is perfectly ok to throw from
550 //! a handler so long as you specify the exception to throw, as in
552 template <class Ex = void const, class Fn>
553 bool with_exception(Fn fn);
555 template <class Ex = void const, class Fn>
556 bool with_exception(Fn fn) const;
558 //! Handle the wrapped expression as if with a series of `catch` clauses,
559 //! propagating the exception if no handler matches.
562 //! exception_wrapper ew{std::runtime_error("goodbye cruel world")};
565 //! [&](std::logic_error const& e) {
566 //! LOG(DFATAL) << "ruh roh";
567 //! ew.throw_exception(); // rethrow the active exception without
568 //! // slicing it. Will not be caught by other
569 //! // handlers in this call.
571 //! [&](std::exception const& e) {
572 //! LOG(ERROR) << ew.what();
575 //! In the above example, any exception _not_ derived from `std::exception`
576 //! will be propagated. To specify a catch-all clause, pass a lambda that
577 //! takes a C-style elipses, as in:
579 //! ew.handle(/*...* /, [](...) { /* handle unknown exception */ } )
582 //! \tparam CatchFns... A pack of unary monomorphic function object types.
583 //! \param fns A pack of unary monomorphic function objects to be treated as
584 //! an ordered list of potential exception handlers.
585 //! \note The handlers may or may not be invoked with an active exception.
586 //! **Do not try to rethrow the exception with `throw;` from within your
587 //! handler -- that is, a throw expression with no operand.** This may
588 //! cause your process to terminate. (It is perfectly ok to throw from
589 //! a handler so long as you specify the exception to throw, as in
591 template <class... CatchFns>
592 void handle(CatchFns... fns);
594 template <class... CatchFns>
595 void handle(CatchFns... fns) const;
599 constexpr exception_wrapper::VTable exception_wrapper::InPlace<Ex>::ops_;
602 * \return An `exception_wrapper` that wraps an instance of type `Ex`
603 * that has been constructed with arguments `std::forward<As>(as)...`.
605 template <class Ex, typename... As>
606 exception_wrapper make_exception_wrapper(As&&... as) {
607 return exception_wrapper{in_place<Ex>, std::forward<As>(as)...};
611 * Inserts `ew.what()` into the ostream `sout`.
615 std::basic_ostream<Ch>& operator<<(
616 std::basic_ostream<Ch>& sout,
617 exception_wrapper const& ew) {
618 return sout << ew.what();
622 * Swaps the value of `a` with the value of `b`.
624 inline void swap(exception_wrapper& a, exception_wrapper& b) noexcept {
628 // For consistency with exceptionStr() functions in ExceptionString.h
629 fbstring exceptionStr(exception_wrapper const& ew);
632 template <typename F>
633 inline exception_wrapper try_and_catch_(F&& f) {
634 return (f(), exception_wrapper());
637 template <typename F, typename Ex, typename... Exs>
638 inline exception_wrapper try_and_catch_(F&& f) {
640 return try_and_catch_<F, Exs...>(std::forward<F>(f));
642 return exception_wrapper(std::current_exception(), ex);
647 //! `try_and_catch` is a simple replacement for `try {} catch(){}`` that allows
648 //! you to specify which derived exceptions you would like to catch and store in
649 //! an `exception_wrapper`.
651 //! Because we cannot build an equivalent of `std::current_exception()`, we need
652 //! to catch every derived exception that we are interested in catching.
654 //! Exceptions should be listed in the reverse order that you would write your
655 //! catch statements (that is, `std::exception&` should be first).
657 //! \par Example Usage:
659 //! // This catches my runtime_error and if I call throw_exception() on ew, it
660 //! // will throw a runtime_error
661 //! auto ew = folly::try_and_catch<std::exception, std::runtime_error>([=]() {
662 //! if (badThingHappens()) {
663 //! throw std::runtime_error("ZOMG!");
667 //! // This will catch the exception and if I call throw_exception() on ew, it
668 //! // will throw a std::exception
669 //! auto ew = folly::try_and_catch<std::exception, std::runtime_error>([=]() {
670 //! if (badThingHappens()) {
671 //! throw std::exception();
675 //! // This will not catch the exception and it will be thrown.
676 //! auto ew = folly::try_and_catch<std::runtime_error>([=]() {
677 //! if (badThingHappens()) {
678 //! throw std::exception();
682 template <typename... Exceptions, typename F>
683 exception_wrapper try_and_catch(F&& fn) {
684 return detail::try_and_catch_<F, Exceptions...>(std::forward<F>(fn));
688 #include <folly/ExceptionWrapper-inl.h>
690 #undef FOLLY_REQUIRES
691 #undef FOLLY_REQUIRES_DEF
693 #pragma GCC diagnostic pop