Skip to content

Cannot call lambda defined in immediate lambda #118187

@LHLaurini

Description

@LHLaurini

The following code compiles on both GCC and MSVC, but is refused by Clang (Godbolt link):

void func_1(auto)
{
    [](auto) consteval
    {
        [](auto)
        {
        }(123);
    };
}

auto func_2()
{
    func_1(123);
}

The error message:

<source>:6:9: error: no matching function for call to object of type '(lambda at <source>:6:9)'
    6 |         [](auto)
      |         ^~~~~~~~
    7 |         {
      |         ~
    8 |         }(123);
      |         ~
<source>:5:5: note: while substituting into a lambda expression here
    5 |     {
      |     ^
<source>:14:5: note: in instantiation of function template specialization 'func_1<int>' requested here
   14 |     func_1(123);
      |     ^
<source>:6:9: note: candidate template ignored: couldn't infer template argument 'auto:1'
    6 |         [](auto)
      |         ^
1 error generated.

From my experimentation:

  • func_1 must be a function template;
  • The outer lambda must be immediate;
  • The outer lambda must be either polymorphic or a lambda template;
  • The inner lambda must be either polymorphic or a lambda template.

Note: the code from which I wrote this test-case is almost the same where I originally found #117676, so there could be some relation (or not).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partydiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issuelambdaC++11 lambda expressionsregression:19Regression in 19 release

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions