forked from jeremy-rifkin/cpptrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom_current_macros.hpp
More file actions
54 lines (49 loc) · 1.71 KB
/
Copy pathfrom_current_macros.hpp
File metadata and controls
54 lines (49 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef CPPTRACE_FROM_CURRENT_MACROS_HPP
#define CPPTRACE_FROM_CURRENT_MACROS_HPP
// https://godbolt.org/z/4MsT6KqP1
#ifdef _MSC_VER
#define CPPTRACE_UNREACHABLE() __assume(false)
#else
#define CPPTRACE_UNREACHABLE() __builtin_unreachable()
#endif
// https://godbolt.org/z/7neGPEche
// gcc added support in 4.8 but I'm too lazy to check the minor version
#if defined(__GNUC__) && (__GNUC__ < 5)
#define CPPTRACE_NORETURN __attribute__((noreturn))
#else
#define CPPTRACE_NORETURN [[noreturn]]
#endif
#ifdef _MSC_VER
#define CPPTRACE_TYPE_FOR(param) \
::cpptrace::detail::argument<void(param)>::type
// this awful double-IILE is due to C2713 "You can't use structured exception handling (__try/__except) and C++
// exception handling (try/catch) in the same function."
#define CPPTRACE_TRY \
try { \
[&]() { \
__try { \
[&]() {
#define CPPTRACE_CATCH(param) \
}(); \
} __except(::cpptrace::detail::exception_filter<CPPTRACE_TYPE_FOR(param)>(GetExceptionInformation())) {} \
}(); \
} catch(param)
#else
#define CPPTRACE_UNWIND_INTERCEPTOR_FOR(param) \
::cpptrace::detail::unwind_interceptor_for<void(param)>
#define CPPTRACE_TRY \
try { \
try {
#define CPPTRACE_CATCH(param) \
} catch(const CPPTRACE_UNWIND_INTERCEPTOR_FOR(param)&) { \
CPPTRACE_UNREACHABLE(); \
/* force instantiation of the init-er */ \
::cpptrace::detail::nop(CPPTRACE_UNWIND_INTERCEPTOR_FOR(param)::init); \
} \
} catch(param)
#endif
#ifdef CPPTRACE_UNPREFIXED_TRY_CATCH
#define TRY CPPTRACE_TRY
#define CATCH(param) CPPTRACE_CATCH(param)
#endif
#endif // CPPTRACE_FROM_CURRENT_MACROS_HPP