Is this the microsoft VC ++ 2010 compiler of the compiler "new auto (enum_type)"

Enviroment: Microsoft Visual Studio 2010 Service Pack 1 (SP1Rel), Windows XP SP3

The VC10 compiler supports the automatic keyword, but the information associated with the type being displayed is not always correct for enumeration.

Example:

#include <type_traits> enum fruit_t { apple = 100, banana = 200, }; int main() { const auto pa = new auto(banana); const auto pb = new fruit_t(banana); static_assert(std::is_same<decltype(pa), decltype(pb)>::value, "not same!"); delete pb; delete pa; } 

There should not be a compiler time error or a runtime error in the above code. But what surprises me is that it compiles normally without any errors or warnings, but it does not work correctly. The debugger reports the main function after exiting:

HEAP CORRUPTION DETERMINED: after% hs block (# 55) at 0x00034878. CRT found that the application was written to memory after heap buffer completion.

therefore, I assume that the compiler may have an error in the output of type "auto". The Assembler window below shows that the requested memeory size in the first "new operator call" is 1 byte, and the second "new operator" is 4 bytes. This suggests that the compiler made a big mistake in the size of the type being displayed.

Do you think this is a compiler error? And are there any bug fixes from Microsoft?

 int main() { 004113C0 push ebp 004113C1 mov ebp,esp 004113C3 sub esp,10Ch 004113C9 push ebx 004113CA push esi 004113CB push edi 004113CC lea edi,[ebp-10Ch] 004113D2 mov ecx,43h 004113D7 mov eax,0CCCCCCCCh 004113DC rep stos dword ptr es:[edi] const auto pa = new auto(banana); 004113DE push 1 004113E0 call operator new (411181h) 004113E5 add esp,4 004113E8 mov dword ptr [ebp-104h],eax 004113EE cmp dword ptr [ebp-104h],0 004113F5 je main+51h (411411h) 004113F7 mov eax,dword ptr [ebp-104h] 004113FD mov dword ptr [eax],0C8h 00411403 mov ecx,dword ptr [ebp-104h] 00411409 mov dword ptr [ebp-10Ch],ecx 0041140F jmp main+5Bh (41141Bh) 00411411 mov dword ptr [ebp-10Ch],0 0041141B mov edx,dword ptr [ebp-10Ch] 00411421 mov dword ptr [pa],edx const auto pb = new fruit_t(banana); 00411424 push 4 00411426 call operator new (411181h) 0041142B add esp,4 0041142E mov dword ptr [ebp-0F8h],eax 00411434 cmp dword ptr [ebp-0F8h],0 0041143B je main+97h (411457h) 0041143D mov eax,dword ptr [ebp-0F8h] 00411443 mov dword ptr [eax],0C8h 00411449 mov ecx,dword ptr [ebp-0F8h] 0041144F mov dword ptr [ebp-10Ch],ecx 00411455 jmp main+0A1h (411461h) 00411457 mov dword ptr [ebp-10Ch],0 00411461 mov edx,dword ptr [ebp-10Ch] 00411467 mov dword ptr [pb],edx static_assert(std::is_same<decltype(pa), decltype(pb)>::value, "not same!"); delete pb; 0041146A mov eax,dword ptr [pb] 0041146D mov dword ptr [ebp-0ECh],eax 00411473 mov ecx,dword ptr [ebp-0ECh] 00411479 push ecx 0041147A call operator delete (411087h) 0041147F add esp,4 delete pa; 00411482 mov eax,dword ptr [pa] 00411485 mov dword ptr [ebp-0E0h],eax 0041148B mov ecx,dword ptr [ebp-0E0h] 00411491 push ecx 00411492 call operator delete (411087h) 00411497 add esp,4 } 
+6
source share
1 answer

Yes, I think this is VS2010 error. Performing the same thing as you (or at least very similar) with XP SP3 (32-bit) and VS2010 SP1, I get exactly the same error. It looks specific to enumerations, since trying it with classes has shown that everything works correctly. I also tried adding another fruit element to the enumeration with a value of 100000, to make sure that it was not something stupid, like your enumeration, with all values โ€‹โ€‹below 255. The same result.

I quickly looked at Microsoft Connect and I donโ€™t see an error report, so I recommend that you enter it. This is the best way to make sure that Microsoft knows and may have fixed it.

+1
source

Source: https://habr.com/ru/post/919317/


All Articles