Search

std::WhateverContainer::iterator::operator->() invokes overloaded "operator&()" of the contained type by Dmitry Me

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 696041
Opened: 10/21/2011 1:58:17 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
This behavior is observed in version 10.0.40219.SP1Rel

I have this code:

class Stored {
public:
    void Whatever();
private:
    void operator&();
};

int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
    std::vector<Stored>(1).begin()->Whatever();
}

that fails to compile with this output:

vector(327): error C2248: 'Stored::operator &' : cannot access private member declared in class 'Stored'

vector(327) refers to this code:

pointer operator->() const
{    // return pointer to class object
return (&**this);
}

The code I showed is of course insane. Yet there're classes like _com_ptr_t and CComPtr that have operator&() overloaded - they can't be used in the scenario I show either. Same seems to apply to other STL containers.

"&" should be replaced with std::addressof() function here.

Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

Compile the code above, inspect the compiler output.

Product Language

English

Operating System

Windows XP

Operating System Language

English

Actual results

Call of overloaded "operator&()" of the contained type is attempted.

Expected results

Call of overloaded "operator&()" of the contained type should not be attempted.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 10/24/2011 at 9:04 AM
Hi Dmitry,

Thanks for this bug report. As Mike notes, this is fixed in the next release. I've therefore closed the bug.

Thanks,

Jim
Posted by MS-Moderator08 [Feedback Moderator] on 10/23/2011 at 8:14 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Mike Danes on 10/21/2011 at 4:29 AM
This works fine in vNext, the code for operator -> is now
pointer operator->() const { return (_STD pointer_traits<pointer>::pointer_to(**this)); }
and pointer_to uses addressof.
Posted by MS-Moderator01 on 10/21/2011 at 2:42 AM
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.