diff --git a/test/unit/from_current.cpp b/test/unit/from_current.cpp index 02d4346..5ca6d46 100644 --- a/test/unit/from_current.cpp +++ b/test/unit/from_current.cpp @@ -13,12 +13,17 @@ using namespace std::literals; +static volatile int truthy = 2; + // NOTE: returning something and then return stacktrace_multi_3(line_numbers) * rand(); is done to prevent TCO even // under LTO https://github.com/jeremy-rifkin/cpptrace/issues/179#issuecomment-2467302052 CPPTRACE_FORCE_NO_INLINE int stacktrace_from_current_3(std::vector& line_numbers) { static volatile int lto_guard; lto_guard = lto_guard + 1; - line_numbers.insert(line_numbers.begin(), __LINE__ + 1); - throw std::runtime_error("foobar"); + if(truthy) { // due to a MSVC warning about unreachable code + line_numbers.insert(line_numbers.begin(), __LINE__ + 1); + throw std::runtime_error("foobar"); + } + return 2; } CPPTRACE_FORCE_NO_INLINE int stacktrace_from_current_2(std::vector& line_numbers) { diff --git a/test/unit/from_current_z.cpp b/test/unit/from_current_z.cpp index e3b837f..cd6de46 100644 --- a/test/unit/from_current_z.cpp +++ b/test/unit/from_current_z.cpp @@ -13,12 +13,17 @@ using namespace std::literals; +static volatile int truthy = 2; + // NOTE: returning something and then return stacktrace_multi_3(line_numbers) * rand(); is done to prevent TCO even // under LTO https://github.com/jeremy-rifkin/cpptrace/issues/179#issuecomment-2467302052 CPPTRACE_FORCE_NO_INLINE int stacktrace_from_current_z_3(std::vector& line_numbers) { static volatile int lto_guard; lto_guard = lto_guard + 1; - line_numbers.insert(line_numbers.begin(), __LINE__ + 1); - throw std::runtime_error("foobar"); + if(truthy) { // due to a MSVC warning about unreachable code + line_numbers.insert(line_numbers.begin(), __LINE__ + 1); + throw std::runtime_error("foobar"); + } + return 2; } CPPTRACE_FORCE_NO_INLINE int stacktrace_from_current_z_2(std::vector& line_numbers) { diff --git a/test/unit/traced_exception.cpp b/test/unit/traced_exception.cpp index ee69d96..58b2e20 100644 --- a/test/unit/traced_exception.cpp +++ b/test/unit/traced_exception.cpp @@ -11,12 +11,17 @@ using namespace std::literals; +static volatile int truthy = 2; + // NOTE: returning something and then return stacktrace_multi_3(line_numbers) * rand(); is done to prevent TCO even // under LTO https://github.com/jeremy-rifkin/cpptrace/issues/179#issuecomment-2467302052 CPPTRACE_FORCE_NO_INLINE int stacktrace_traced_object_3(std::vector& line_numbers) { static volatile int lto_guard; lto_guard = lto_guard + 1; - line_numbers.insert(line_numbers.begin(), __LINE__ + 1); - throw cpptrace::runtime_error("foobar"); + if(truthy) { // due to a MSVC warning about unreachable code + line_numbers.insert(line_numbers.begin(), __LINE__ + 1); + throw cpptrace::runtime_error("foobar"); + } + return 2; } CPPTRACE_FORCE_NO_INLINE int stacktrace_traced_object_2(std::vector& line_numbers) {