Home Dashboard Directory Help
Search

Sizeof a member function pointer of an incomplete type messes another sizeof after the type has been defined by tailsu


Status: 

Closed
 as By Design Help for as By Design


0
0
Sign in
to vote
Type: Bug
ID: 338226
Opened: 4/15/2008 1:59:22 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Use the following code to reproduce the bug. Note that if the first sizeof is removed, the code compiles cleanly.

struct bar;
int a = sizeof(void (bar::*)());

struct bar
{
    void foo();
};
char x[sizeof(&bar::foo) == 16 ? -1 : 1];
Details
Sign in to post a comment.
Posted by Microsoft on 4/18/2008 at 9:45 AM
Hi: this is By-Design. By having that first sizeof you are forcing the compiler to decide what the pointer-to-member representation for the class bar is. As the class bar is not yet defined the compiler has to choose the most pessimistic (i.e. largest) representation for the pointer-to-member. Once it has choosen a representation it sticks with it -- even it it turns out that when that the definition of bar is such that it could have used a more optimial representation. Do avoid this you need to give the compiler more information - something like:

struct __single_inheritance bar;
int a = sizeof(void (bar::*)());

struct bar
{
    void foo();
};

char x[sizeof(&bar::foo) == 16 ? -1 : 1];

Jonathan Caves
Visual C++ Compiler Team

Posted by Microsoft on 4/15/2008 at 8:34 PM
Thanks for your feedback.

We are escalating 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.

Thank you,
Visual Studio Product Team
Sign in to post a workaround.