Bug 54995 - Converting lambda to C-style functions when there is template
Summary: Converting lambda to C-style functions when there is template
Status: RESOLVED DUPLICATE of bug 56447
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, c++-lambda
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2012-10-20 06:06 UTC by Temtaime
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-12-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 niXman 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)
Comment 2 Paolo Carlini 2012-10-20 08:31:12 UTC
May be duplicate of other known issues about lambdas vs templates.
Comment 3 Jonathan Wakely 2012-12-06 16:00:31 UTC
I think the code should be rejected.

Possibly related to Bug 55532

(Temtaine, in future please provide code, not a URL to some other site, thanks)
Comment 4 Jason Merrill 2013-03-04 18:10:39 UTC
56447 has a more compact testcase.

*** This bug has been marked as a duplicate of bug 56447 ***