public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60463] New: Lambda function can call a non-const member function with const this
@ 2014-03-07 23:32 topi.musto at gmail dot com
  2014-04-12 19:37 ` [Bug c++/60463] " momchil.velikov at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: topi.musto at gmail dot com @ 2014-03-07 23:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60463
           Summary: Lambda function can call a non-const member function
                    with const this
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: topi.musto at gmail dot com

The following C++11 translation unit shouldn't compile, because g is non-const
and f is const:

struct A
{
    void g()
    {
    }

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

Yet it compiles with g++ -std=c++11 -Wall -Wextra

Tested with
g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1, and
g++ (GCC) 4.9.0 20140307 (experimental)

Note that calling the function with this->g(); gives the expected error
message:
"error: passing ‘const A’ as ‘this’ argument of ‘void A::g()’ discards
qualifiers [-fpermissive]"
>From gcc-bugs-return-445763-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Mar 07 23:35:16 2014
Return-Path: <gcc-bugs-return-445763-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 22348 invoked by alias); 7 Mar 2014 23:35:16 -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 22303 invoked by uid 48); 7 Mar 2014 23:35:13 -0000
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/60450] [4.7/4.8 Regression] ICE with SHAPE intrinsic
Date: Fri, 07 Mar 2014 23:35:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: fortran
X-Bugzilla-Version: 4.8.2
X-Bugzilla-Keywords: ice-on-valid-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: kargl at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: janus at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-60450-4-5B25El2S9b@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60450-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60450-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-03/txt/msg00632.txt.bz2
Content-length: 534

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #6 from kargl at gcc dot gnu.org ---
(In reply to janus from comment #4)
> (In reply to janus from comment #3)
> > The following patch is sufficient to fix it on 4.8:
>
> ... and regtests cleanly.

Patch is OK with a testcase.


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

* [Bug c++/60463] Lambda function can call a non-const member function with const this
  2014-03-07 23:32 [Bug c++/60463] New: Lambda function can call a non-const member function with const this topi.musto at gmail dot com
@ 2014-04-12 19:37 ` momchil.velikov at gmail dot com
  2014-05-09 20:08 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: momchil.velikov at gmail dot com @ 2014-04-12 19:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Momchil Velikov <momchil.velikov at gmail dot com> ---
Just stumbled upon essentially the same problem with

c++ (GCC) 4.10.0 20140412 (experimental) [master revision
094da06:e25c6c8:855372a3d3c40b76fed8ff368d37b77d14a488eb]

#include <iostream>

struct S {
  void foo() const;
  void bar();
  int x = 0;
};

void S::foo() const {
  auto f = [&]() { bar(); };
  f();
  std::cout << x << std::endl;
}

void S::bar() { ++x; }

int main() {
  S s;
  s.foo();
  return 0;
}


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

* [Bug c++/60463] Lambda function can call a non-const member function with const this
  2014-03-07 23:32 [Bug c++/60463] New: Lambda function can call a non-const member function with const this topi.musto at gmail dot com
  2014-04-12 19:37 ` [Bug c++/60463] " momchil.velikov at gmail dot com
@ 2014-05-09 20:08 ` jason at gcc dot gnu.org
  2014-05-20 20:26 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  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=60463

--- Comment #2 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++/60463] Lambda function can call a non-const member function with const this
  2014-03-07 23:32 [Bug c++/60463] New: Lambda function can call a non-const member function with const this topi.musto at gmail dot com
  2014-04-12 19:37 ` [Bug c++/60463] " momchil.velikov at gmail dot com
  2014-05-09 20:08 ` jason at gcc dot gnu.org
@ 2014-05-20 20:26 ` jason at gcc dot gnu.org
  2014-09-22 19:22 ` jason at gcc dot gnu.org
  2015-02-05 14:28 ` gene at staubsaal dot de
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2014-05-20 20:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.10.0

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed on trunk.


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

* [Bug c++/60463] Lambda function can call a non-const member function with const this
  2014-03-07 23:32 [Bug c++/60463] New: Lambda function can call a non-const member function with const this topi.musto at gmail dot com
                   ` (2 preceding siblings ...)
  2014-05-20 20:26 ` jason at gcc dot gnu.org
@ 2014-09-22 19:22 ` jason at gcc dot gnu.org
  2015-02-05 14:28 ` gene at staubsaal dot de
  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=60463

--- Comment #4 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

* [Bug c++/60463] Lambda function can call a non-const member function with const this
  2014-03-07 23:32 [Bug c++/60463] New: Lambda function can call a non-const member function with const this topi.musto at gmail dot com
                   ` (3 preceding siblings ...)
  2014-09-22 19:22 ` jason at gcc dot gnu.org
@ 2015-02-05 14:28 ` gene at staubsaal dot de
  4 siblings, 0 replies; 6+ messages in thread
From: gene at staubsaal dot de @ 2015-02-05 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

gene at staubsaal dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gene at staubsaal dot de

--- Comment #5 from gene at staubsaal dot de ---
*** Bug 64915 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2015-02-05 14:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-07 23:32 [Bug c++/60463] New: Lambda function can call a non-const member function with const this topi.musto at gmail dot com
2014-04-12 19:37 ` [Bug c++/60463] " momchil.velikov at gmail dot com
2014-05-09 20:08 ` jason at gcc dot gnu.org
2014-05-20 20:26 ` jason at gcc dot gnu.org
2014-09-22 19:22 ` jason at gcc dot gnu.org
2015-02-05 14:28 ` gene at staubsaal dot de

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