Search

Access to private members in a C++ Class from outside is allowed without compile errors (VS2012) by Herwig Bachner

Closed
as Deferred Help for as Deferred

1
1
Sign in
to vote
Type: Bug
ID: 774022
Opened: 12/11/2012 6:00:30 AM
Access Restriction: Public
1
Workaround(s)
1
User(s) can reproduce this bug
if I use a private declared member in a class the compiler ignores this and compiles this without any warnings or errors. Only VS2012 intellisense marks this as an error. I thing this a bug.

Details (expand)

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

Visual Studio 2012

Steps to reproduce

Sample Code:

class class1{
private:
    union{
        struct{
            unsigned a:8;
            unsigned b:8;
            unsigned c:4;
            unsigned d:4;
            unsigned e:8;
        };
        unsigned int l;
    };
public:
    class1(){l=0;}
};


void functionxy(){
    class1 x;
    x.c |= 0x03;
}

Product Language

English

Operating System

Windows 8

Operating System Language

English

Actual results

Compiles without errors and warnings

Expected results

error: member is inaccesable
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 12/11/2012 at 6:14 PM
Thank you for submitting feedback on Visual Studio 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 Microsoft on 12/11/2012 at 6:51 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.
Posted by UnitUniverse on 12/15/2012 at 5:01 PM
class class1{
private:
union {
struct{
unsigned a:8;
unsigned b:8;
unsigned c:4;
unsigned d:4;
unsigned e:8;
}tagi;
unsigned int l;
}tago;
public:
class1(){tago.l=0;}
};


void functionxy(){
class1 x;
x.tago.l = 0x0; // C2248
x.tago.tagi.c |= 0x03; // C2248
}