public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56537] New: [C++11] lambda expression treats members as const
@ 2013-03-05 14:07 Martin.vGagern at gmx dot net
  2013-03-05 14:10 ` [Bug c++/56537] " Martin.vGagern at gmx dot net
  0 siblings, 1 reply; 2+ messages in thread
From: Martin.vGagern at gmx dot net @ 2013-03-05 14:07 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56537
           Summary: [C++11] lambda expression treats members as const
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: Martin.vGagern@gmx.net


The following code won't compile on GCC 4.7.2:

#include <vector>
template<typename T> struct Foo {
  std::vector<int> member;
  Foo() {
    auto f = [this]() {
#if 0
      this->
#endif
      member.push_back(42);
    };
  };
};
void bar() { Foo<int> foo; }

The compiler reports:

foo.cc: In lambda function:
foo.cc:9:26: error: no matching function for call to
‘std::vector<int>::push_back(int) const’
foo.cc:9:26: note: candidates are:
In file included from …/4.7.2/include/g++-v4/vector:65:0,
                 from foo.cc:1:
…/4.7.2/include/g++-v4/bits/stl_vector.h:881:7: note: void std::vector<_Tp,
_Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc =
std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int] <near match>
…/4.7.2/include/g++-v4/bits/stl_vector.h:881:7: note:   no known conversion for
implicit ‘this’ parameter from ‘const std::vector<int>*’ to ‘std::vector<int>*’
…/4.7.2/include/g++-v4/bits/stl_vector.h:899:7: note: void std::vector<_Tp,
_Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int;
_Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int] <near
match>
…/4.7.2/include/g++-v4/bits/stl_vector.h:899:7: note:   no known conversion for
implicit ‘this’ parameter from ‘const std::vector<int>*’ to ‘std::vector<int>*’

But the "this" parameter in this case is a "Foo* const", not a "const
std::vector<int>*". There are several ways to avoid this problem: one can
enable the "this->" prefix currently disabled using the preprocessor. Or one
can make the whole lambda mutable. But as this appears to be a strange corner
case only encountered in the interplay of several templates, I doubt that this
is intended behaviour.


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

* [Bug c++/56537] [C++11] lambda expression treats members as const
  2013-03-05 14:07 [Bug c++/56537] New: [C++11] lambda expression treats members as const Martin.vGagern at gmx dot net
@ 2013-03-05 14:10 ` Martin.vGagern at gmx dot net
  0 siblings, 0 replies; 2+ messages in thread
From: Martin.vGagern at gmx dot net @ 2013-03-05 14:10 UTC (permalink / raw)
  To: gcc-bugs


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

Martin von Gagern <Martin.vGagern at gmx dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #1 from Martin von Gagern <Martin.vGagern at gmx dot net> 2013-03-05 14:10:14 UTC ---
Looks like a duplicate of bug #54277. Sorry for the noise, but I mixed up my
searches and missed that hit while writing the report.

*** This bug has been marked as a duplicate of bug 54277 ***


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

end of thread, other threads:[~2013-03-05 14:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-05 14:07 [Bug c++/56537] New: [C++11] lambda expression treats members as const Martin.vGagern at gmx dot net
2013-03-05 14:10 ` [Bug c++/56537] " Martin.vGagern at gmx dot net

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).