Search

Cannot call static member functions of template types directly from lambdas in C++. by Benjamin Lindley

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 703088
Opened: 11/13/2011 12:57:01 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
0
User(s) can reproduce this bug
Failure to compile when trying to call a static member function of a type T from a lambda within a function template.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010

Steps to reproduce

Try to compile the following program as standard C++.

struct Foo {
    static void bar() { }
};

template<typename T>
void example()
{
    []() { T::bar(); }();
}

int main()
{
    example<Foo>();
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

2 compilation errors:

testio.cpp(8): error C2653: 'T' : is not a class or namespace name
testio.cpp(8): error C3861: 'bar': identifier not found

Expected results

Successful compilation.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 12/9/2011 at 7:25 PM
Hi -

We have fixed this issue for the next major release. Thank you for reporting it.

Andy Rich
Visual C++ QA
Posted by MS-Moderator07 [Feedback Moderator] on 11/13/2011 at 6:52 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Posted by MS-Moderator01 on 11/13/2011 at 1:42 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Benjamin Lindley on 11/13/2011 at 1:00 PM
Get a function pointer to the static member function, then call that from within the lambda:

template<typename T>
void example()
{
auto func = T::bar;
[]() { func(); }();
}