Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore "Check failure stack trace" message on LOG(FATAL) #1110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2541,8 +2541,11 @@ LogMessageFatal::LogMessageFatal(const char* file, int line,
: LogMessage(file, line, result) {}

LogMessageFatal::~LogMessageFatal() noexcept(false) {
Flush();
LogMessage::Fail();
// We really want [[noreturn]] on the destructor so the compiler can use it.
// We really just want to reuse the parent class's destructor since it has all
// the right logic in it.
LogMessage::~LogMessage();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The destructors in a class hierarchy are generally called in the reverse order of construction. Explicitly invoking the base class destructor means that the base class destructor will be called a second time. However, at that point the object no longer exists. I suspect this is UB territory.

Fail();
}

namespace logging {
Expand Down
6 changes: 6 additions & 0 deletions src/logging_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1586,3 +1586,9 @@ TEST(Logging, FatalThrow) {
ScopedExit<decltype(restore_fail)> restore{restore_fail};
EXPECT_THROW({ LOG(FATAL) << "must throw to fail"; }, std::logic_error);
}

TEST(DeathLogging, ErrorMessage) {
ASSERT_DEATH({ LOG(FATAL) << "foo"; }, "Check failure stack trace");
ASSERT_DEATH({ LOG_AT_LEVEL(google::LogSeverity::FATAL) << "foo"; },
"Check failure stack trace");
}