Bug 55828 - problem with access to static method from lambda in another method
Summary: problem with access to static method from lambda in another method
Status: RESOLVED DUPLICATE of bug 51494
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2012-12-29 10:07 UTC by Vladimir Bayda
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-01-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Bayda 2012-12-29 10:07:50 UTC
It looks like an issue.
When I'm trying to access to static method from lambda defined in another method I'm getting following error:

Compilation finished with errors:
source.cpp: In lambda function:
source.cpp:7:22: error: 'this' was not captured for this lambda function


Sample code:
struct Test
{
   static void func1() {}
   void func2() 
   {
      auto f = []() {
         Test::func1();
      };
   }
};
int main()
{}

It's could be easily reproduced on gcc 4.7.3 and bellow.
I haven't checked iso standard for right behavior - but it seems msvc and clang compilers work fine with this example.
Also it gets ok when I pass this to lambda.
Comment 1 Daniel Krügler 2013-01-07 23:09:07 UTC
The problem also exists for gcc 4.8.0 20121209 (experimental), I agree that the code should be accepted.
Comment 2 Jason Merrill 2013-03-04 18:15:07 UTC
Same issue as 51494.

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