This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/54947] New: [4.7/4.8 Regression] [C++11] lambda cannot capture-by-copy inside braced-init-list
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 17 Oct 2012 13:11:19 +0000
- Subject: [Bug c++/54947] New: [4.7/4.8 Regression] [C++11] lambda cannot capture-by-copy inside braced-init-list
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54947
Bug #: 54947
Summary: [4.7/4.8 Regression] [C++11] lambda cannot
capture-by-copy inside braced-init-list
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: redi@gcc.gnu.org
Blocks: 54367
struct X
{
template<typename L>
X(L)
{ }
};
template<typename A>
void
test()
{
int i = 0;
A a_ok_1( [=] { return i; } ); // OK
A a_ok_2( [i] { return i; } ); // OK
A a_err_1{ [i] { return i; } }; // error
A a_err_2{ [=] { return i; } }; // error
}
int main()
{
test<X>();
}
lam.cc:17:17: error: the value of âiâ is not usable in a constant expression
A a_err_1{ [i] { return i; } }; // error
^
lam.cc:12:9: note: âint iâ is not const
int i = 0;
^
lam.cc:18:17: error: expression â<erroneous-expression> =
<erroneous-expression>â is not a constant-expression
A a_err_2{ [=] { return i; } }; // error
^
There's no error when using direct-initialization, only list-initialization.
No error if test() is not a function template.
Works fine with 4.6 and clang++