C++ parameter pack compile error occurs in the capture block of the lambda from difference between gcc 4.8.2 and 4.9.4;

김륜현 winxp4333@naver.com
Wed Sep 1 03:49:52 GMT 2021


Dear sir, 
 
Hi, I tried to compile my source code using gcc-linaro-aarch64-linux-gnu-4.8-2013.09-01_linux(gcc 4.8.2)
 
The error occurred like below
 
lamb.cpp:5:19: error: expected ‘,’ before ‘...’ token
  auto zzz = [&args...](int ccc) -> int {
                   ^
lamb.cpp:5:19: error: expected identifier before ‘...’ token
lamb.cpp:5:22: error: parameter packs not expanded with ‘...’:
  auto zzz = [&args...](int ccc) -> int {
                      ^
lamb.cpp:5:22: note:         ‘args’
lamb.cpp: In instantiation of ‘struct solve(const int&, Args&& ...) [with Args = {}]::__lambda0’:
lamb.cpp:9:6:   required from ‘void solve(const int&, Args&& ...) [with Args = {}]’
lamb.cpp:15:10:   required from here
lamb.cpp:5:15: error: using invalid field ‘solve(const int&, Args&& ...)::__lambda0::__args’
  auto zzz = [&args...](int ccc) -> int {
               ^
 
Here, I attach the code
 
#include <stdio.h>
 
template <typename... Args>
void solve(const int &aa, Args &&... args) {
        auto zzz = [&args...](int ccc) -> int {
                int res = 1;
                printf("%d",ccc);
                return res + ccc;
        }(10);
        printf("zzz : %d\n",zzz);
}
 
int main()
{
        solve(10);
}
 
 
Solve function syntax refer to the template parameter pack "Args" as r-value. 
And use "args" as a reference in the capture block of Lambda.
 
Is It right? but, the compile error occurred.
 
I think that this issue cause is that C++11 standard not implements this syntax in gcc 4.8 / implements in gcc 4.9 
Because I eventually changed the toolchain to gcc-linaro-4.9-2016.02-x86_64_aarch64-linux-gnu(gcc4.9.4) and Build was success.()
And when i searched this issue in http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html, this issue was mentioned in No.904
 
Is There workaround in gcc 4.8?(I want to change toolchain version. but, I should use gcc 4.8)
 


More information about the Gcc-help mailing list