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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 1 Sept 2021 at 04:51, 김륜현 via Gcc-help <gcc-help@xxxxxxxxxxx> wrote:
>
> 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

See https://gcc.gnu.org/pipermail/gcc-help/2021-September/140667.html

> Is There workaround in gcc 4.8?(I want to change toolchain version. but, I should use gcc 4.8)

You could create a tuple from the parameter pack and capture the
tuple, but it will be awkward to access the elements. You should just
use a newer compiler if you want to compile C++11 code.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux