public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60755] New: lambda capturing `this` doesn't honor the const qualifier of the enclosing member function
@ 2014-04-04  0:05 filip.roseen at gmail dot com
  2014-04-04  0:08 ` [Bug c++/60755] " filip.roseen at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: filip.roseen at gmail dot com @ 2014-04-04  0:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60755
           Summary: lambda capturing `this` doesn't honor the const
                    qualifier of the enclosing member function
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: filip.roseen at gmail dot com

Created attachment 32539
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32539&action=edit
testcase.cpp

#include <iostream>

struct A {
  void f () const { std::cerr << "const "; }
  void f ()       { std::cerr << "non-const "; }

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

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


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

The above prints "non-const const", even though the type of `this`
should be `A const *` in both `f()` and `this->f()` inside the
anonymous lambda.

[ Note: `clang` will generate a binary which correctly outputs "const const" ]

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

[expr.prim.lambda]p18 states:

  > If `this` is captured, each odr-use of `this` is transformed into an
  > access to the corresponding unnamed data member of the closure type,
  > cast (5.4) to the type of `this`.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-22 19:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-04  0:05 [Bug c++/60755] New: lambda capturing `this` doesn't honor the const qualifier of the enclosing member function filip.roseen at gmail dot com
2014-04-04  0:08 ` [Bug c++/60755] " filip.roseen at gmail dot com
2014-04-12 19:43 ` [Bug c++/60755] lambda capturing `this` doesn't honor " momchil.velikov at gmail dot com
2014-05-09 20:08 ` jason at gcc dot gnu.org
2014-06-06  9:28 ` paolo.carlini at oracle dot com
2014-09-22 19:22 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).