Bug 55914 - [C++11] Pack expansion fails in lambda expressions
Summary: [C++11] Pack expansion fails in lambda expressions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, rejects-valid
: 57817 (view as bug list)
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2013-01-09 10:08 UTC by Daniel Krügler
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.9.0
Known to fail: 4.7.2, 4.8.0
Last reconfirmed: 2013-01-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2013-01-09 10:08:19 UTC
The following code, compiled with 

-Wall -std=c++11 -pedantic

is rejected by gcc 4.7.2 and gcc 4.8.0 20130106 (experimental):

//---------------------
struct S {
  int foo(){ return 0; }
};

template<class... Args>
void evaluate(Args...){}

template <class... Args>
void bar(Args... args) {
  evaluate(args.foo()...); // OK
  auto lmb = [=](){ evaluate(args.foo()...); }; // Error
  lmb();
}

int main() {
  S s{};
  bar(s);
}
//---------------------

"11|error: parameter packs not expanded with '...':|
11|note:         'args'|
In instantiation of 'void bar(Args ...) [with Args = {S}]':|
17|required from here|
11|error: using invalid field 'bar(Args ...)::__lambda0::__args'|
"

The problem also occurs for class member expressions of the form E1->E2 instead of E1.E2.
Comment 1 Paolo Carlini 2013-01-09 10:23:56 UTC
I suspect this is just a different manifestation of PR41933.
Comment 2 Daniel Krügler 2013-01-09 10:39:29 UTC
(In reply to comment #1)
> I suspect this is just a different manifestation of PR41933.

Thanks Paolo, I partially agree. Indeed the problem is not depending on class member expressions (so the issue title should be fixed), a simplified example can be written as:

//--------------------
struct S {};

template<class... Args>
void evaluate(Args...){}

template <class... Args>
void bar(Args... args) {
  evaluate(args...); // OK
  auto lmb = [=](){ evaluate(args...); }; // Error
  lmb();
}

int main() {
  S s{};
  bar(s);
}
//--------------------

with the error:

"9|error: parameter packs not expanded with '...':|
9|note:         'args'|
9|error: expansion pattern 'args' contains no argument packs|
|In instantiation of 'void bar(Args ...) [with Args = {S}]':|
15|required from here|
9|error: using invalid field 'bar(Args ...)::__lambda0::__args'|"

The reason why I hesitate to agree with that being a dup of bug 41933 is due to the fact that the corresponding example there depends on a language extension described in

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#904

that is not part of C++11. I do think though, that my revised example above is indeed conforming C++11 because it does not depend on that grammar extension.

Please keep that in mind when considering the category change to DUP, because that would have impact on which versions of gcc to patch. For example, I assume that any CWG defect 904 association would presumably not be applied to gcc 4.7.2.
Comment 3 Paolo Carlini 2013-01-09 10:56:03 UTC
Thanks Daniel, don't worry I'm not going to close anything for now. But we should really clarify in PR41933 that the issue isn't about C++11 proper.
Comment 4 Paolo Carlini 2013-01-09 10:59:54 UTC
Daniel, are you sure PR41933 isn't C++11 proper? I gather that the corresponding Core issue (which at the time Jason also referenced) went into CD2, thus isn't just C++11?!?
Comment 5 Daniel Krügler 2013-01-09 11:37:49 UTC
(In reply to comment #4)
You are right, I missed the CD2 tag
Comment 6 Paolo Carlini 2013-07-04 08:32:10 UTC
*** Bug 57817 has been marked as a duplicate of this bug. ***
Comment 7 Paolo Carlini 2013-09-21 08:57:09 UTC
Fixed for 4.9.0 by the patch which fixed c++/41933.
Comment 8 Balakrishnan B 2014-11-20 15:49:22 UTC
Is this bug fixed in 4.8.3? I don't find here

Known to work:	4.9.0
Known to fail:	4.7.2, 4.8.0
Comment 9 Jaak Ristioja 2016-03-29 14:57:48 UTC
(In reply to Balakrishnan B from comment #8)
> Is this bug fixed in 4.8.3? I don't find here
> 
> Known to work:	4.9.0
> Known to fail:	4.7.2, 4.8.0

Apparently this is was not backported to the 4.8 series, as 4.8.5 still fails with the simplified example in comment #3.