This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/60463] New: Lambda function can call a non-const member function with const this


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]"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]