Skip to content

Commit fbf0543

Browse files
authored
Make return address extraction work on more compilers (#845)
1 parent e439dcc commit fbf0543

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

strings/base_error.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11

2+
#if defined(_MSC_VER)
3+
#include <intrin.h>
4+
#define WINRT_IMPL_RETURNADDRESS() _ReturnAddress()
5+
#elif defined(__GNUC__)
6+
#define WINRT_IMPL_RETURNADDRESS() __builtin_extract_return_addr(__builtin_return_address(0))
7+
#else
8+
#define WINRT_IMPL_RETURNADDRESS() nullptr
9+
#endif
10+
211
namespace winrt::impl
312
{
413
struct heap_traits
@@ -428,7 +437,7 @@ WINRT_EXPORT namespace winrt
428437
{
429438
if (winrt_throw_hresult_handler)
430439
{
431-
winrt_throw_hresult_handler(0, nullptr, nullptr, _ReturnAddress(), result);
440+
winrt_throw_hresult_handler(0, nullptr, nullptr, WINRT_IMPL_RETURNADDRESS(), result);
432441
}
433442

434443
if (result == impl::error_bad_alloc)
@@ -508,7 +517,7 @@ WINRT_EXPORT namespace winrt
508517
{
509518
if (winrt_to_hresult_handler)
510519
{
511-
return winrt_to_hresult_handler(_ReturnAddress());
520+
return winrt_to_hresult_handler(WINRT_IMPL_RETURNADDRESS());
512521
}
513522

514523
try
@@ -607,4 +616,6 @@ namespace winrt::impl
607616
}
608617
return result;
609618
}
610-
}
619+
}
620+
621+
#undef WINRT_IMPL_RETURNADDRESS

0 commit comments

Comments
 (0)