https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102363

            Bug ID: 102363
           Summary: source_location in await_transform has function_name
                    referring to internal coroutine funclet rather than
                    source-level function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

When a promise_type::await_transform() has a defaulted argument of
source_location::current(), it refers to the location of the co_await that
triggered the await_transform. This is really useful for building runtime
diagnostics and tracing. The file/line/column fields all seem to be filled out
correctly, however, the function_name field refers to an internal funclet that
the coroutine function is split into. I think it would be more useful if it had
the original corountine function name since that is what users will be
expecting.

Example: https://godbolt.org/z/sbMsPG8Eq

Output:
  good: /app/example.cpp:20:43: example func()
  bad: /app/example.cpp:25:14: void func(func()::_Z4funcv.frame*)

Source (compiled with just -std=c++20):
#include <coroutine>
#include <source_location>
#include <cstdio>
struct example {
    struct promise_type {
        std::suspend_never initial_suspend() { return {}; }
        std::suspend_never final_suspend() noexcept { return {}; }
        void unhandled_exception() { throw; }
        example get_return_object() { return {}; }
        void return_void() {}

        auto await_transform(const char* dummy, std::source_location l =
std::source_location::current()) {
            printf("bad: %s:%u:%u: %s\n", l.file_name(), l.line(), l.column(),
l.function_name());
            return std::suspend_never();
        }
    };
};

example func() {
    auto l = std::source_location::current();
    printf("good: %s:%u:%u: %s\n", l.file_name(), l.line(), l.column(),
l.function_name());

    // bad location points here:
    //       v
    co_await "pretend this is an awaitable";
}

int main() {
    func();
}
  • [Bug c++/102363] New: source_lo... redbeard0531 at gmail dot com via Gcc-bugs

Reply via email to