mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 06:20:11 +01:00
Previously, the program exit was triggered by the destructor. Unfortunately, C++ doesn't make it precisely clear where the destructor is run, and Clang doesn't generate reliable debug information for that to give good backtraces. Among other things, when combining separate cleanup regions in Clang there may be no single canonical location. Instead, move the ExitingStream system to use an explicit low-precedence operator overload to flush the output and exit. This ensures the stream and other actions are completed first but then immediately exits the program in a way that has a definitive source location and produces reliable backtraces. I've tried to add comments and helpers to make this as clear as possible given that it is a subtle and surprising issue. Co-authored-by: Geoff Romer <gromer@google.com>