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

* [Bug c++/60755] lambda capturing `this` doesn't honor the const qualifier of the enclosing member function
  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 ` 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
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: filip.roseen at gmail dot com @ 2014-04-04  0:08 UTC (permalink / raw)
  To: gcc-bugs

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 () { }
>From gcc-bugs-return-448247-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Apr 04 00:49:23 2014
Return-Path: <gcc-bugs-return-448247-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 27338 invoked by alias); 4 Apr 2014 00:49:23 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 27320 invoked by uid 48); 4 Apr 2014 00:49:17 -0000
From: "rth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug debug/60756] New: var-tracking selects wrong registers
Date: Fri, 04 Apr 2014 00:49:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: debug
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: rth at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-60756-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-04/txt/msg00267.txt.bz2
Content-length: 2244

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`756

            Bug ID: 60756
           Summary: var-tracking selects wrong registers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rth at gcc dot gnu.org

The smallest example I can find is gcc.dg/guality/param-3.c.

The parameter "str" is passed in x0+x1, and immediately copied into
the call-saved registers x22+x23, where they stay for the duration
of the function.

But var-tracking works (or appears to work) back-to-front, taking
the location of the variable from the src rather than the dest of
a copy.  Thus we get

(note 43 1 44 (var_location str (reg:TI 0 x0 [ str ])) NOTE_INSN_VAR_LOCATION)
...
(note 35 34 28 NOTE_INSN_PROLOGUE_END)
(insn 28 35 46 (set (reg:DI 22 x22 [orig:75 str ] [75])
        (reg:DI 0 x0 [ str ])) z.c:18 34 {*movdi_aarch64}
     (expr_list:REG_DEAD (reg:DI 0 x0 [ str ])
        (nil)))
(note 46 28 29 (var_location str (reg:TI 0 x0 [ str ])) NOTE_INSN_VAR_LOCATION)
(insn 29 46 3 (set (reg:DI 23 x23 [ str+8 ])
        (reg:DI 1 x1 [ str+8 ])) z.c:18 34 {*movdi_aarch64}
     (expr_list:REG_DEAD (reg:DI 1 x1 [ str+8 ])
        (nil)))
...
(insn 8 5 47 (set (reg:SI 0 x0)
        (reg:SI 2 x2 [orig:76 a ] [76])) z.c:19 33 {*movsi_aarch64}
     (nil))
(note 47 8 9 (var_location str (nil)) NOTE_INSN_VAR_LOCATION)
...
(note 53 16 26 (var_location str (nil)) NOTE_INSN_VAR_LOCATION)
(insn 26 53 54 (set (reg:DI 0 x0)
        (reg:DI 22 x22 [orig:75 str ] [75])) z.c:21 34 {*movdi_aarch64}
     (expr_list:REG_DEAD (reg:DI 22 x22 [orig:75 str ] [75])
        (nil)))
(note 55 54 27 (var_location str (reg:TI 22 x22 [orig:75 str ] [75]))
NOTE_INSN_VAR_LOCATION)

where we have the initial prologue describing str as residing in x0,
a clobber of x0 and the death of str, then the copy of str back to
an outgoing parameter and suddenly str is once again live in x22.

At minimum it would seem that taking DECL_RTL into account when
examining these assignments would be a good start.  When copying into
its canonical location, it would seem a great time to alter the
live range.


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

* [Bug c++/60755] lambda capturing `this` doesn't honor const qualifier of the enclosing member function
  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 ` momchil.velikov at gmail dot com
  2014-05-09 20:08 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: momchil.velikov at gmail dot com @ 2014-04-12 19:43 UTC (permalink / raw)
  To: gcc-bugs

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

Momchil Velikov <momchil.velikov at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |momchil.velikov at gmail dot com

--- Comment #2 from Momchil Velikov <momchil.velikov at gmail dot com> ---
Possible duplicate of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60463


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

* [Bug c++/60755] lambda capturing `this` doesn't honor const qualifier of the enclosing member function
  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
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2014-05-09 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Fri May  9 20:07:45 2014
New Revision: 210292

URL: http://gcc.gnu.org/viewcvs?rev=210292&root=gcc&view=rev
Log:
    PR c++/60463
    PR c++/60755
    * lambda.c (lambda_expr_this_capture): Add new parameter
    add_capture_p controlling whether the functions will try to
    capture 'this' via the default capture.
    (maybe_resolve_dummy): Likewise.
    * cp-tree.h: Adjust prototypes.
    * call.c, semantics.c: Change callers of these functions.
    * call.c (build_new_method_call_1): Use the actual 'this' that
    would be potentially captured for the overload resolution, instead
    of the dummy object.

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


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

* [Bug c++/60755] lambda capturing `this` doesn't honor const qualifier of the enclosing member function
  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
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-06  9:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.10.0

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I think we can close this as fixed in 4.10.0.


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

* [Bug c++/60755] lambda capturing `this` doesn't honor const qualifier of the enclosing member function
  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
                   ` (3 preceding siblings ...)
  2014-06-06  9:28 ` paolo.carlini at oracle dot com
@ 2014-09-22 19:22 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2014-09-22 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Mon Sep 22 19:22:11 2014
New Revision: 215478

URL: https://gcc.gnu.org/viewcvs?rev=215478&root=gcc&view=rev
Log:
    PR c++/63320
    PR c++/60463
    PR c++/60755
    * lambda.c (maybe_resolve_dummy, lambda_expr_this_capture): Handle
    not finding 'this'.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/lambda.c
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C


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