Skip to content

Commit

Permalink
Resolve msvc warning/error
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Nov 12, 2024
1 parent e41f89e commit 855210e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions test/unit/from_current.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& 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<int>& line_numbers) {
Expand Down
9 changes: 7 additions & 2 deletions test/unit/from_current_z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& 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<int>& line_numbers) {
Expand Down
9 changes: 7 additions & 2 deletions test/unit/traced_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& 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<int>& line_numbers) {
Expand Down

0 comments on commit 855210e

Please sign in to comment.