public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ parameter pack compile error occurs in the capture block of the lambda from difference between gcc 4.8.2 and 4.9.4;
@ 2021-09-01  3:49 김륜현
  2021-09-01  9:50 ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: 김륜현 @ 2021-09-01  3:49 UTC (permalink / raw)
  To: gcc-help

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)
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* 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;
  2021-09-01  3:49 C++ parameter pack compile error occurs in the capture block of the lambda from difference between gcc 4.8.2 and 4.9.4; 김륜현
@ 2021-09-01  9:50 ` Jonathan Wakely
  2021-09-01 10:22   ` 김륜현
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2021-09-01  9:50 UTC (permalink / raw)
  To: 김륜현; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* 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;
  2021-09-01  9:50 ` Jonathan Wakely
@ 2021-09-01 10:22   ` 김륜현
  2021-09-02  4:14     ` 김륜현
  0 siblings, 1 reply; 5+ messages in thread
From: 김륜현 @ 2021-09-01 10:22 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

I'm the author of https://gcc.gnu.org/pipermail/gcc-help/2021-September/140667.html.
 
The code in this mail thread  was simplified for the example.
You said I could use a tuple, but it actually has to be applied to below code.
 
[this, &args...](const MachineBasicBlock *MBB, const VarTy &,
 
I will try to modify code by using tuple
 
If It is failed, I will conclude this issue as gcc version issue.
 
Thanks for answer
 
On Wed, 1 Sept 2021 at 04:51, 김륜현 via Gcc-help <gcc-help@gcc.gnu.org> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* 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;
  2021-09-01 10:22   ` 김륜현
@ 2021-09-02  4:14     ` 김륜현
  2021-09-02  6:26       ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: 김륜현 @ 2021-09-02  4:14 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

I attempted to do refactoring by creating tuple from parameter pack 
 
It is successful. 
 
But I should unpack tuple to parameter pack again.... 
(because I should transfer argument as parameter pack form like below code) 
 
void testFunc(Args ... args)
{
auto tupleVar = make_tuple(args...);
..........
auto lambdaF = [this, &tupleVar ] (int a) -> {
auto bbb = bbbFunc(int q, forward<Arg>(args)...);
}; 
}
 
I tried to search for a way to unpack tuple to parameter pack
 
However, there is a way to access each element, but there seems to be no way to use a tuple as a parameter pack.
 
Is There any solution about this problem?
 
If I can change the type for a parameter in function bbbFunc, 
I can define the function without using lambda expression and pass args... as argument form rather than capture block
 
But it is not possible(I can't modify bbbFunc)
 
I'm the author of https://gcc.gnu.org/pipermail/gcc-help/2021-September/140667.html.

The code in this mail thread  was simplified for the example.
You said I could use a tuple, but it actually has to be applied to below code.

[this, &args...](const MachineBasicBlock *MBB, const VarTy &,

I will try to modify code by using tuple

If It is failed, I will conclude this issue as gcc version issue.

Thanks for answer

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* 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;
  2021-09-02  4:14     ` 김륜현
@ 2021-09-02  6:26       ` Jonathan Wakely
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Wakely @ 2021-09-02  6:26 UTC (permalink / raw)
  To: 김륜현; +Cc: gcc-help

On Thu, 2 Sep 2021, 05:14 김륜현, <winxp4333@naver.com> wrote:

> I attempted to do refactoring by creating tuple from parameter pack
>
>
>
> It is successful.
>
>
>
> But I should unpack tuple to parameter pack again....
>
> (because I should transfer argument as parameter pack form like below
> code)
>
>
>
> void testFunc(Args ... args)
>
> {
>
> auto tupleVar = make_tuple(args...);
>
> ..........
>
> auto lambdaF = [this, &tupleVar ] (int a) -> {
>
> auto bbb = bbbFunc(int q, forward<Arg>(args)...);
>
> };
>
> }
>
>
>
> I tried to search for a way to unpack tuple to parameter pack
>
>
>
> However, there is a way to access each element, but there seems to be no
> way to use a tuple as a parameter pack.
>
>
>
> Is There any solution about this problem?
>

Yes, but it's complicated, and you will keep finding more and more problems.

If you want to compile modern C++ code then use a newer compiler.



>
> If I can change the type for a parameter in function bbbFunc,
>
> I can define the function without using lambda expression and pass args...
> as argument form rather than capture block
>
>
>
> But it is not possible(I can't modify bbbFunc)
>
>
> I'm the author of
> https://gcc.gnu.org/pipermail/gcc-help/2021-September/140667.html.
>
> The code in this mail thread  was simplified for the example.
> You said I could use a tuple, but it actually has to be applied to below
> code.
>
> [this, &args...](const MachineBasicBlock *MBB, const VarTy &,
>
> I will try to modify code by using tuple
>
> If It is failed, I will conclude this issue as gcc version issue.
>
> Thanks for answer
>
> On Wed, 1 Sept 2021 at 04:51, 김륜현 via Gcc-help <gcc-help@gcc.gnu.org>
> 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.
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-02  6:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  3:49 C++ parameter pack compile error occurs in the capture block of the lambda from difference between gcc 4.8.2 and 4.9.4; 김륜현
2021-09-01  9:50 ` Jonathan Wakely
2021-09-01 10:22   ` 김륜현
2021-09-02  4:14     ` 김륜현
2021-09-02  6:26       ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).