This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49763] New: [C++0x] A reference is not correctly captured by [=]
- From: "iorate_stage at yahoo dot co.jp" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 16 Jul 2011 16:28:10 +0000
- Subject: [Bug c++/49763] New: [C++0x] A reference is not correctly captured by [=]
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49763
Summary: [C++0x] A reference is not correctly captured by [=]
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: iorate_stage@yahoo.co.jp
When a reference to an integral type (e.g. int) is captured by [=] of a lambda
expression, the value of the captured data is not one of the referenced object,
but the address of that.
int main()
{
int const &i = 42;
[=] ()
{
std::cout << i << '\n';
<< *(int *)i << '\n';
} ();
// 2293396
// 42
}
When the referenced type is a floating point type, ICE occurs.
int main()
{
double const &d = 3.14;
[=] ()
{
std::cout << d << '\n';
} ();
}
-- ***.cpp: In function 'int main()':
-- ***.cpp:***:8: internal compiler error: in convert_move, at expr.c:324
-- Please submit a full bug report,
-- with preprocessed source if appropriate.
-- See <http://gcc.gnu.org/bugs.html> for instructions.
When the referenced type is a class type, or the reference is explictly
captured by name, it works.