Skip to content

Pack expansion error in nested generic lambda in variable template #63677

Closed
@ericniebler

Description

@ericniebler

Compile with -std=c++20:

template <class>
inline constexpr auto fun =
  []<class... Ts>(Ts... ts) {
    return [... us = (Ts&&) ts]<class Fun>(Fun&& fn) mutable {
      return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...);
    };
  };

int main() {
  auto s = fun<int>(1,2,3,4);
}

Demo on Godbolt: https://godbolt.org/z/Kjq8PEGn1

Result:

<source>:6:58: error: pack expansion contains parameter pack 'Ts' that has a different length (1 vs. 4) from outer parameter packs
      return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...);
                                                ~~       ^
<source>:11:20: note: in instantiation of function template specialization '(anonymous class)::operator()<int, int, int, int>' requested here
  auto s = fun<int>(1,2,3,4);
                   ^
1 error generated.

Expected:
Success

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions