This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/54995] Converting lambda to C-style functions when there is template


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

--- Comment #1 from niXman <i.nixman at gmail dot com> 2012-10-20 07:15:28 UTC ---

> App crash:
> http://liveworkspace.org/code/3d5e51c9059ea4f37ce2d0d23739d374

More detailed output.

source:
#include <stdio.h>

typedef void(*void_func)();

void foo(void_func f) {
   f();
}

class C {
public:
   template<typename F>
   void bar(F f) {
      auto func = [f, this] {
         f();
         printf("%d!!!\n", k);
      };

      foo(func);
   }

private:
   int k = 10;
};

int main() {
   printf("%s\n", "ping1");
   auto func = [] {
      printf("called\n");
   };
   printf("%s\n", "ping2");
   C().bar(func);
   printf("%s\n", "ping3");
}


run:
$ g++-4.7.2 -std=c++11 ice.cpp -oice && ./ice
ping1
ping2
called
Segmentation fault (core dumped)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]