Search code examples
c++stack-tracec++23

Why is C++23 stacktrace_entry different from source_location?


class stacktrace_entry {
public:
  string description() const;
  string source_file() const;
  uint_least32_t source_line() const;
  /* ... */
};
struct source_location {
  // source location field access
  constexpr uint_least32_t line() const noexcept;
  constexpr uint_least32_t column() const noexcept;
  constexpr const char* file_name() const noexcept;
  constexpr const char* function_name() const noexcept;
  /* ... */
};

They serve basically the same purpose, why do they have differences, specifically no column in stacktrace_entry, or not even share the same class?


Solution

  • The answers from the proposal author.

    Regarding returning std::string:

    As it is stated in P0881R7: "Unfortunately this is a necessarity on some platforms, where getting source line requires allocating or where source file name returned into a storage provided by user."

    Regarding column:

    Most popular solutions for non-Windows platforms do not provide a source_column(). At the moment std::stacktrace is a minimal subset of abilities of all platforms, so the column is missing. This could be changed later, the addition seems quite simple for C++ standardization.