Skip to content

std::source_location::function_name is ambiguous with function local types #129083

@bebuch

Description

@bebuch

https://godbolt.org/z/4jx1dxE3E

#include <iostream>
#include <source_location>

template <typename T>
auto PrettyName() -> char const* {
    return std::source_location::current().function_name();
}

void normal() {
    struct A{};
    std::cout << "normal: " << PrettyName<A>() << '\n';
}

struct A;

int main() {
    auto lambda = []{
        struct A{};
        std::cout << "lambda: " << PrettyName<A>() << '\n';
    };

    std::cout << "global: " << PrettyName<A>() << '\n';
    normal();
    lambda();
}

clang output:

global: const char *PrettyName() [T = A]
normal: const char *PrettyName() [T = A]
lambda: const char *PrettyName() [T = A]

The GCC output is not ambiguous:

global: const char* PrettyName() [with T = A]
normal: const char* PrettyName() [with T = normal()::A]
lambda: const char* PrettyName() [with T = main()::<lambda()>::A]

I think it might be an good idea to change __PRETTY_FUNCTION__ output for function local types to something similar of what GCC does. Its annoying to look into a log file and see a type that exists globally while another function locale type was used. Thats pretty hard to debug.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions