http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60463
Bug ID: 60463
Summary: Lambda function can call a non-const member function
with const this
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: topi.musto at gmail dot com
The following C++11 translation unit shouldn't compile, because g is non-const
and f is const:
struct A
{
void g()
{
}
void f() const
{
[this]() { g(); }();
}
};
Yet it compiles with g++ -std=c++11 -Wall -Wextra
Tested with
g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1, and
g++ (GCC) 4.9.0 20140307 (experimental)
Note that calling the function with this->g(); gives the expected error
message:
"error: passing ‘const A’ as ‘this’ argument of ‘void A::g()’ discards
qualifiers [-fpermissive]"