Search

Friend Template Classes and Lambda Functions by killogre

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 736965
Opened: 4/15/2012 1:52:31 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
A template class is declared a friend of some class, and tries to access the private members of the friend inside a lambda function
Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

class Foo {
    template<typename T> friend class Bar;
    int priv;
};

template<typename T>
class Bar {
public:

    void func() {
        Foo foo;
        foo.priv = 17; // compiles
        auto lambda_func = [](Foo& _foo) { _foo.priv = 17; }; // doesn't compile
    }
};

void test() {
    Bar<int> bar;
    bar.func();
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

compilation error:
error C2248: 'Foo::priv' : cannot access private member declared in class 'Foo'

Expected results

should compile
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 4/16/2012 at 11:41 AM
Hi:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by MS-Moderator08 [Feedback Moderator] on 4/15/2012 at 11:02 PM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 4/15/2012 at 6:45 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.