Home Dashboard Directory Help
Search

Incorrect code generated when returning struct by value and compiling for x86. by Johan Lindvall


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 649953
Opened: 3/7/2011 9:06:56 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

Returning a declared struct by value causes the x86 compiler to generate incorrect code (debug and release).
Details
Sign in to post a comment.
Posted by Microsoft on 6/14/2011 at 8:51 AM
Hi Johan,
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.
    Here is a simplified repro:

a.cpp

struct A {int i;};
 
template <typename T> T f();
 
int main()
{
    f<A>();
}

b.cpp:

template <typename T> T f();
 
struct A;
 
template <> A f<A>();
 
struct A {int i;};
 
template <>
A f<A>()
{
    A q = {};
    return q;
}

cl a.cpp b.cpp

    a.exe will crash at runtime.

    The workaround is to do the explicit instantiation "template <> A f<A>();" after the definition of A.

Xiang Fan
Visual C++ Team
Posted by Microsoft on 3/9/2011 at 11:58 AM
Thanks for reporting this issue. We're still investigating the problem, but it looks like the root cause is different header inclusion order in the two .cpp files. As a work around you can change your header inclusion order in each .cpp file to be the same.

thanks,
VC++ Code Generation and Optimization Team
Posted by Microsoft on 3/7/2011 at 7:13 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 review. We will contact you if we require any additional information.
Posted by Microsoft on 3/7/2011 at 9:13 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.
File Name Submitted By Submitted On File Size  
msvc_nro.zip 3/7/2011 4 KB