llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Pack expansion error in nested generic lambda in variable template

Open ericniebler opened this issue 3 years ago • 2 comments

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

ericniebler avatar Jul 05 '23 01:07 ericniebler

@llvm/issue-subscribers-clang-frontend

llvmbot avatar Jul 05 '23 04:07 llvmbot

https://reviews.llvm.org/D154716 should fix this

MitalAshok avatar Jul 07 '23 14:07 MitalAshok