[Bug c++/51494] Legal program rejection - capturing "this" when using static method inside lambda

2015-11-23 Thread arthur.j.odwyer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

Arthur O'Dwyer  changed:

   What|Removed |Added

 CC||arthur.j.odwyer at gmail dot 
com

--- Comment #11 from Arthur O'Dwyer  ---
Is there a workaround available for GCC 4.6.3?
That is, I have some code that looks like

class A {
static A *unwrap(void *p);
static void api_helper(void *p) { A *a = unwrap(p); ... }
void init() { register_with_api(_helper); }
};

where "api_helper" exists only to conform to the requirements of the external
API.
To reduce the surface area of the class, I'd like to refactor this into
something like

class A {
static A *unwrap(void *p);
void init() {
auto api_helper = [](void *a) { A *a = unwrap(p); ... };
register_with_api(api_helper);
}
};

but at the moment I'm hitting this bug in gcc (Ubuntu/Linaro 4.6.3-1ubuntu5)
4.6.3 because "api_helper" happens to also want to use some static members of
A.

I understand if there's no workaround (beyond "upgrade to gcc 4.8"), but if
there IS one, I'd like to know it!

[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2013-03-08 Thread jason at gcc dot gnu.org


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



--- Comment #9 from Jason Merrill jason at gcc dot gnu.org 2013-03-08 
16:03:57 UTC ---

Author: jason

Date: Fri Mar  8 16:03:48 2013

New Revision: 196549



URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=196549

Log:

PR c++/51494

PR c++/51884

PR c++/56222

* tree.c (maybe_dummy_object): Don't capture 'this'.

* semantics.c (maybe_resolve_dummy): New.

(finish_non_static_data_member): Use it.

(finish_qualified_id_expr): Don't test is_dummy_object.

* cp-tree.h: Declare maybe_resolve_dummy.

* call.c (build_new_method_call_1): Use it.



Added:

trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this11.C

Modified:

trunk/gcc/cp/ChangeLog

trunk/gcc/cp/call.c

trunk/gcc/cp/cp-tree.h

trunk/gcc/cp/semantics.c

trunk/gcc/cp/tree.c


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2013-03-08 Thread jason at gcc dot gnu.org


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



Jason Merrill jason at gcc dot gnu.org changed:



   What|Removed |Added



 Status|ASSIGNED|RESOLVED

 Resolution||FIXED

   Target Milestone|--- |4.8.0



--- Comment #10 from Jason Merrill jason at gcc dot gnu.org 2013-03-08 
16:10:48 UTC ---

Fixed for 4.8.


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2013-03-05 Thread jason at gcc dot gnu.org


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



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 |


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2013-03-04 Thread jason at gcc dot gnu.org


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



Jason Merrill jason at gcc dot gnu.org changed:



   What|Removed |Added



 CC||vladimir.bayda at gmail dot

   ||com



--- Comment #8 from Jason Merrill jason at gcc dot gnu.org 2013-03-04 
18:15:08 UTC ---

*** Bug 55828 has been marked as a duplicate of this bug. ***


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2012-12-07 Thread kpx1894 at gmail dot com


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



kpx1894 kpx1894 at gmail dot com changed:



   What|Removed |Added



 CC||kpx1894 at gmail dot com



--- Comment #7 from kpx1894 kpx1894 at gmail dot com 2012-12-07 15:18:03 UTC 
---

This bug is still present in GCC 4.7.2. There are cases where capturing this

(as a workaround) is not possible:

--

#include iostream



struct Test

{

void (*get())()

{

return [](){ Test::sf(); };

}



static void sf()

{

std::cout  Test::sf  std::endl;

}



};



int main()

{

Test test;



auto f = test.get();

(*f)();

}

--


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2012-08-16 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 Status|ASSIGNED|NEW
 AssignedTo|paolo.carlini at oracle dot |unassigned at gcc dot
   |com |gnu.org

--- Comment #6 from Paolo Carlini paolo.carlini at oracle dot com 2012-08-16 
09:53:36 UTC ---
Not actively working on this.


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2012-06-04 Thread gcc-bugx at mailinator dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

gcc-bugx at mailinator dot com changed:

   What|Removed |Added

 CC||gcc-bugx at mailinator dot
   ||com

--- Comment #4 from gcc-bugx at mailinator dot com 2012-06-04 08:21:54 UTC ---
Probably related error: this capture ignored on explicit instantiation.

8---
struct A
{
static void f() {}

template typename T
void foo()
{
[this] () { f(); };
}
};

template void A::fooint();
8---


Compiler version  output:

$ g++ -std=c++11 -c -v y.cc
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --enable-languages=c,c++ --prefix=/home/x
Thread model: posix
gcc version 4.7.0 (GCC) 
COLLECT_GCC_OPTIONS='-std=c++11' '-c' '-v' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
 /home/x/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/cc1plus -quiet -v
-D_GNU_SOURCE y.cc -quiet -dumpbase y.cc -mtune=generic -march=x86-64 -auxbase
y -std=c++11 -version -o /tmp/ccdFvfri.s
GNU C++ (GCC) version 4.7.0 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.0, GMP version 4.3.2, MPFR version
3.0.0-p8, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
/home/x/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include
#include ... search starts here:
#include ... search starts here:
 /home/x/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0

/home/x/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/x86_64-unknown-linux-gnu

/home/x/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/backward
 /home/x/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include
 /usr/local/include
 /home/x/include
 /home/x/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.7.0 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.0, GMP version 4.3.2, MPFR version
3.0.0-p8, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ...
y.cc: In instantiation of ‘A::foo() [with T = int]::lambda()’:
y.cc:8:4:   required from ‘struct A::foo() [with T = int]::lambda()’
y.cc:8:3:   required from ‘void A::foo() [with T = int]’
y.cc:11:27:   required from here
y.cc:8:17: error: ‘this’ was not captured for this lambda function


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2012-06-04 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

--- Comment #5 from Jason Merrill jason at gcc dot gnu.org 2012-06-04 
19:35:40 UTC ---
The testcases in comments 2 and 4 are PR 53137, which is fixed for 4.7.1.


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2012-05-03 Thread luto at mit dot edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

Andy Lutomirski luto at mit dot edu changed:

   What|Removed |Added

 CC||luto at mit dot edu

--- Comment #2 from Andy Lutomirski luto at mit dot edu 2012-05-03 21:53:18 
UTC ---
This seems to have gotten worse in gcc 4.7.  This code is now rejected as well:

This code:

struct A
{
  static void func1() {}
};

templatetypename T
struct B : public A
{
  void func2() const
  {
func3([]{ func1(); });
  }

  templatetypename Func
  void func3(Func f) const
  {
  }
};

template class Bint;

The error is:

template_bug.cc: In instantiation of ‘BT::func2() const [with T =
int]::lambda()’:
template_bug.cc:11:22:   required from ‘struct BT::func2() const [with T =
int]::lambda()’
template_bug.cc:11:5:   required from ‘void BT::func2() const [with T = int]’
template_bug.cc:20:16:   required from here
template_bug.cc:11:16: error: redeclaration of ‘const Bint* const
BT::func2() const [with T = int]::lambda()::__this’
template_bug.cc:11:22: note: previous declaration ‘const Bint* const
BT::func2() const [with T = int]::lambda()::__this’
template_bug.cc:11:16: error: redeclaration of ‘const Bint* const this’
template_bug.cc:11:22: error: ‘const Bint* const this’ previously declared
here
template_bug.cc:15:8: error: ‘void BT::func3(Func) const [with Func =
BT::func2() const [with T = int]::lambda(); T = int]’, declared using local
type ‘BT::func2() const [with T = int]::lambda()’, is used but never
defined [-fpermissive]

Your patch fixes this test case, too.


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2012-05-03 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

--- Comment #3 from Paolo Carlini paolo.carlini at oracle dot com 2012-05-03 
23:04:35 UTC ---
A slightly improved patch is available here:

  http://gcc.gnu.org/ml/gcc-patches/2012-02/msg00429.html

but see the comments. I'm not sure I will be able soon enough to address the
non-trivial comments and post a new version.


[Bug c++/51494] Legal program rejection - capturing this when using static method inside lambda

2011-12-21 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2011-12-22
 CC|ulidtko at gmail dot com|
 AssignedTo|unassigned at gcc dot   |paolo.carlini at oracle dot
   |gnu.org |com
 Ever Confirmed|0   |1

--- Comment #1 from Paolo Carlini paolo.carlini at oracle dot com 2011-12-22 
01:38:46 UTC ---
On it.