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 Thu, 2 Sep 2021, 05:14 김륜현, <winxp4333@xxxxxxxxx> 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@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