This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51927] New: [C++0x] Cannot access non-static members in initializer
- From: "gccearlyadopter at trash-mail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 21 Jan 2012 00:30:43 +0000
- Subject: [Bug c++/51927] New: [C++0x] Cannot access non-static members in initializer
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51927
Bug #: 51927
Summary: [C++0x] Cannot access non-static members in
initializer
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: gccearlyadopter@trash-mail.com
GCC47 doesn't allow to access non-static members in non-static member
initialization. The following program fails to compile with the error "invalid
use of non-static data member 'testee::l1'".
#include <iostream>
#include <functional>
using std::cout;
using std::endl;
struct testee
{
std::function<void()> l1 = []()
{
cout << "world" << endl;
};
std::function<void()> l2 = [=]()
{
cout << "hello " << endl;
l1();
};
};
int main()
{
testee t;
t.l2();
}
Taking the address of l1 in the lambda expression used to initialize l2 is also
refused by GCC.