Skip to content

Templated lambda invoked in compile time doesn't instantiate if declared inside templated function #100897

Open
@GuzevArtem

Description

@GuzevArtem

Example below compiles fine under MSVC and GCC

template<typename>
[[nodiscard]]
constexpr auto foo() noexcept
{
    constexpr auto extract_size = []<typename argument_t>() constexpr -> int
    {
        return 1;
    };
    //return extract_size.template operator()<int>(); // works
    constexpr int result = extract_size.template operator()<int>(); // undefined function 'operator()<int>'
    return result;
}

int main() {
    return foo<void>();
}

If foo isn't templated, it compiles fine.

https://godbolt.org/z/6bj4d6zef

:10:19: error: constexpr variable 'result' must be initialized by a constant expression :10:50: note: undefined function 'operator()' cannot be used in a constant expression

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"lambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions