public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified
@ 2012-08-15 22:21 travis at gockelhut dot com
  2012-08-16  6:24 ` [Bug c++/54277] " daniel.kruegler at googlemail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: travis at gockelhut dot com @ 2012-08-15 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54277
           Summary: Template class member referred to with implicit this
                    inside lambda is incorrectly const-qualified
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: travis@gockelhut.com


Created attachment 28025
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28025
reproduce -- fails in 4.7.0, works in 4.6.3

When a template class attempts to call a member's member function inside of a
lambda function AND the member is referred to through an implicit this, the
member will be erroneously const-qualified.

    struct Used
    {
        void foo() { }
    };

    template <typename>
    struct S
    {
        Used x;

        void bar()
        {
            auto f = [this] { x.foo(); };
            f();
        }
    };

Yields the following compilation error with g++ 4.7:

capture-this-const.cpp: In lambda function:
capture-this-const.cpp:13:27: error: no matching function for call to
‘Used::foo() const’
capture-this-const.cpp:13:27: note: candidate is:
capture-this-const.cpp:3:7: note: void Used::foo() <near match>
capture-this-const.cpp:3:7: note:   no known conversion for implicit ‘this’
parameter from ‘const Used*’ to ‘Used*’

---

This can be compiled properly by explicitly adding this->:

            auto f = [this] { this->x.foo(); };

---

$> g++ -v
Using built-in specs.
COLLECT_GCC=g++-4.7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.7.0-7ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --disable-bootstrap --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.0 (Ubuntu/Linaro 4.7.0-7ubuntu3)


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

* [Bug c++/54277] Template class member referred to with implicit this inside lambda is incorrectly const-qualified
  2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
@ 2012-08-16  6:24 ` daniel.kruegler at googlemail dot com
  2012-08-29 14:54 ` leo at yuriev dot ru
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-08-16  6:24 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-08-16 06:24:26 UTC ---
The problem still exists in gcc 4.8.0 20120729 (experimental)


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

* [Bug c++/54277] Template class member referred to with implicit this inside lambda is incorrectly const-qualified
  2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
  2012-08-16  6:24 ` [Bug c++/54277] " daniel.kruegler at googlemail dot com
@ 2012-08-29 14:54 ` leo at yuriev dot ru
  2012-10-06  0:08 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: leo at yuriev dot ru @ 2012-08-29 14:54 UTC (permalink / raw)
  To: gcc-bugs

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

Leo Yuriev <leo at yuriev dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |leo at yuriev dot ru

--- Comment #2 from Leo Yuriev <leo at yuriev dot ru> 2012-08-29 14:54:15 UTC ---
+1, just confirm


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

* [Bug c++/54277] Template class member referred to with implicit this inside lambda is incorrectly const-qualified
  2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
  2012-08-16  6:24 ` [Bug c++/54277] " daniel.kruegler at googlemail dot com
  2012-08-29 14:54 ` leo at yuriev dot ru
@ 2012-10-06  0:08 ` paolo.carlini at oracle dot com
  2013-02-15 19:25 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-06  0:08 UTC (permalink / raw)
  To: gcc-bugs


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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-06
     Ever Confirmed|0                           |1


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

* [Bug c++/54277] Template class member referred to with implicit this inside lambda is incorrectly const-qualified
  2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
                   ` (2 preceding siblings ...)
  2012-10-06  0:08 ` paolo.carlini at oracle dot com
@ 2013-02-15 19:25 ` jason at gcc dot gnu.org
  2013-03-05 14:10 ` Martin.vGagern at gmx dot net
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-02-15 19:25 UTC (permalink / raw)
  To: gcc-bugs


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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2013-02-15 19:25:31 UTC ---
Created attachment 29472
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29472
patch

I'll be checking this in after 4.8 branches.


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

* [Bug c++/54277] Template class member referred to with implicit this inside lambda is incorrectly const-qualified
  2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
                   ` (3 preceding siblings ...)
  2013-02-15 19:25 ` jason at gcc dot gnu.org
@ 2013-03-05 14:10 ` Martin.vGagern at gmx dot net
  2013-03-17  2:42 ` jason at gcc dot gnu.org
  2013-03-23 16:57 ` [Bug c++/54277] [4.7/4.8 regression] " jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ 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=54277

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Martin.vGagern at gmx dot
                   |                            |net

--- Comment #4 from Martin von Gagern <Martin.vGagern at gmx dot net> 2013-03-05 14:10:14 UTC ---
*** Bug 56537 has been marked as a duplicate of this bug. ***


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

* [Bug c++/54277] Template class member referred to with implicit this inside lambda is incorrectly const-qualified
  2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
                   ` (4 preceding siblings ...)
  2013-03-05 14:10 ` Martin.vGagern at gmx dot net
@ 2013-03-17  2:42 ` jason at gcc dot gnu.org
  2013-03-23 16:57 ` [Bug c++/54277] [4.7/4.8 regression] " jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-17  2:42 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-17 02:41:35 UTC ---
Author: jason
Date: Sun Mar 17 02:41:22 2013
New Revision: 196747

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196747
Log:
    PR c++/54277
    * cp-tree.h (WILDCARD_TYPE_P): Split out from...
    (MAYBE_CLASS_TYPE_P): ...here.
    * semantics.c (lambda_capture_field_type): Only build a
    magic decltype for wildcard types.
    (lambda_proxy_type): Likewise.
    (finish_non_static_data_member): Get the quals from
    the object.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/semantics.c


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

* [Bug c++/54277] [4.7/4.8 regression] Template class member referred to with implicit this inside lambda is incorrectly const-qualified
  2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
                   ` (5 preceding siblings ...)
  2013-03-17  2:42 ` jason at gcc dot gnu.org
@ 2013-03-23 16:57 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-23 16:57 UTC (permalink / raw)
  To: gcc-bugs


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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.3
            Summary|Template class member       |[4.7/4.8 regression]
                   |referred to with implicit   |Template class member
                   |this inside lambda is       |referred to with implicit
                   |incorrectly const-qualified |this inside lambda is
                   |                            |incorrectly const-qualified

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-23 16:57:12 UTC ---
Fixed for 4.7.3.


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

end of thread, other threads:[~2013-03-23 16:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-15 22:21 [Bug c++/54277] New: Template class member referred to with implicit this inside lambda is incorrectly const-qualified travis at gockelhut dot com
2012-08-16  6:24 ` [Bug c++/54277] " daniel.kruegler at googlemail dot com
2012-08-29 14:54 ` leo at yuriev dot ru
2012-10-06  0:08 ` paolo.carlini at oracle dot com
2013-02-15 19:25 ` jason at gcc dot gnu.org
2013-03-05 14:10 ` Martin.vGagern at gmx dot net
2013-03-17  2:42 ` jason at gcc dot gnu.org
2013-03-23 16:57 ` [Bug c++/54277] [4.7/4.8 regression] " 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).