[Bug c++/60755] lambda capturing `this` doesn't honor the const qualifier of the enclosing member function

filip.roseen at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Apr 4 00:08:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60755

--- Comment #1 from Filip Roséen <filip.roseen at gmail dot com> ---
Reduced testcase:

-----------------------------------------------------------------

struct A {
  void f () { }

  void g () const {
    [this] { f (); } ();
  }
};

int main () {
  A {}.g ();
}

-----------------------------------------------------------------

`gcc` compiles this with no diagnostics, `clang` correctly issues:


  testcase.cpp:5:14: error: member function 'f' not viable: 'this'
                            argument has type 'const A', but function
                            is not marked const
      [this] { f (); } ();
             ^
  testcase.cpp:2:8: note: 'f' declared here
    void f () { }


More information about the Gcc-bugs mailing list