Home Dashboard Directory Help

Visual C++ doesn't respect the access modifier for operator member function templates by itessier


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 649496
Opened: 3/4/2011 1:10:15 PM
Access Restriction: Public
User(s) can reproduce this bug



Visual C++ doesn't respect the access modifier (protected, or private) for operators that are member function templates.

For example:

class A
    template<typename Y>
    void operator= (const Y y);

int _tmain(int argc, _TCHAR* argv[])
    A a;
    a = 0;

    return 0;

This code fails with the following linker error:

error LNK2019: unresolved external symbol "private: void __thiscall A::operator=<int>(int)" (??$?4H@A@@AAEXH@Z) referenced in function _wmain

Instead, it should fail with a compilation error:

error C2248: 'A::operator =' : cannot access private member declared in class 'A'

This bug can be reproduced in Visual C++ 2005, 2008, and 2010. As a comparison, gcc 4.4.5 is able to detect the error.

IntelliSense in Visual C++ 2010 is able to detect the error:

IntelliSense: "void A::operator=(Y y) [with Y=int]" (declared at line 11) is inaccessible
Sign in to post a comment.
Posted by Microsoft on 3/11/2011 at 5:12 PM

Thank you for reporting this. Yes, this was a bug in our compiler and had been reported by multiple customers. We have fixed it and the fix will be available in the next major release.

Here's what I see now:
t.cpp(10) : error C2248: 'A::operator =' : cannot access private member declared in class 'A'
        t.cpp(5) : see declaration of 'A::operator ='
        t.cpp(2) : see declaration of 'A'

Ulzii Luvsanbat
Windows C++ Team
Posted by Microsoft on 3/6/2011 at 6:04 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 Microsoft on 3/4/2011 at 1:14 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.