Skip to content

[Clang] nontrivial use of std::source_location::current() in a default argument fails #80630

@pdimov

Description

@pdimov

The following

#include <source_location>

#define BOOST_CURRENT_LOCATION_PTR \
    []( char const* fn ) \
    { \
        static constexpr std::source_location loc = std::source_location::current(); \
        return &loc; \
    }( std::source_location::current().function_name() )

auto f( std::source_location const* loc = BOOST_CURRENT_LOCATION_PTR )
{
    return loc;
}

auto g()
{
    return f();
}

fails (for Clang trunk and Clang 17, with both libstdc++ and libc++) with

error: cannot take address of consteval function 'current' outside of an immediate invocation

(https://godbolt.org/z/jqqxq6njh)

GCC, MSVC accept.

The example is simplified to the point of doing not much at all, but it started out as something doing useful things. :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions