Jump to content

Recommended Posts

Posted

I think I've discovered a compiler bug.

 

Well, I don't know wether this is known or not, but if I could get confirmations with both the VS2005 and VS2008 c++ compilers.

 

I'm working my way through [the safe bool idiom article], and specifically, i found the error implementing the OperatorNot class:

 

// operator! version

class Testable {

bool not_ok_;

public:

explicit Testable(bool b=true):not_ok_(!b) {}

 

bool operator!() const {

return not_ok_;

}

};

 

Notice the not (!) in the initialiser.

 

When run it does not initialise the not_ok member to false, when instanitating the class like:

Testable test;

Here's the disassembly of the constructor:

public:

explicit Testable(bool b=true):ok_(b) {}

004115F0 push ebp

004115F1 mov ebp,esp

004115F3 sub esp,0CCh

004115F9 push ebx

004115FA push esi

004115FB push edi

004115FC push ecx

004115FD lea edi,[ebp-0CCh]

00411603 mov ecx,33h

00411608 mov eax,0CCCCCCCCh

0041160D rep stos dword ptr es:[edi]

0041160F pop ecx

00411610 mov dword ptr [ebp-8],ecx

00411613 mov eax,dword ptr [this]

00411616 mov cl,byte ptr

00411619 mov byte ptr [eax],cl

0041161B mov eax,dword ptr [this]

0041161E pop edi

0041161F pop esi

00411620 pop ebx

00411621 mov esp,ebp

00411623 pop ebp

00411624 ret 4

WTF.

I've checked multiple times, and the original source does have the !.

Yet when I switch to the disassembly view, and single-step into the constructor, it shows it (the bit marked in red) without the !. The bit embolded is the actual native code setting the member.

Am I missing something ?

 

This is using VS2005sp1 (c1xx.dll version 14.0.50727.762)

 

 

 

 

 

More...

 

View All Our Microsoft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...