{{ message }}
Repository navigation
Conversation
Adds support for formatting std::stacktrace and std::stacktrace_entry from <stacktrace> (C++23, __cpp_lib_stacktrace). - stacktrace_entry formats as 'function at file:line' when symbols are available, or as a hex address otherwise - stacktrace formats one indexed entry per line: '#N description' - Both formatters inherit string_view specs (width, fill, align) - Guarded by __cpp_lib_stacktrace for portability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR adds formatting support for
std::stacktraceandstd::stacktrace_entryfrom the C++23<stacktrace>header.Motivation
There is currently no way to format
std::stacktraceorstd::stacktrace_entrywith {fmt}. These types are widely useful for diagnostic and logging output, and are a natural fit alongside the existingstd::exceptionandstd::source_locationformatters already infmt/std.h.Example usage this PR enables:
Changes
include/fmt/std.hformatter<std::stacktrace_entry>— formats asfunction at file:linewhen debug symbols are available, or as a hex address otherwiseformatter<std::stacktrace>— formats one indexed entry per line as#N descriptionformatter<string_view>to support fill, align, and width specs<stacktrace>is guarded byFMT_CPLUSPLUS >= 202302L && FMT_HAS_INCLUDE(<stacktrace>) && defined(__cpp_lib_stacktrace)FMT_EXPORTfor correct C++20 module supporttest/std-test.ccTEST(std_test, stacktrace_entry)— verifies description, source location formatting, and width/alignment specsTEST(std_test, stacktrace)— verifies indexed multi-line output, newline count, and alignmentTEST(std_test, stacktrace_empty)— verifies an empty stacktrace formats to""without crashingdoc/api.mdstd::stacktraceandstd::stacktrace_entryunder the standard library formatters section with a description of the output formatCompatibility
#ifdef __cpp_lib_stacktrace