Search

Linker error passing unique_ptr to function with C++/CLI by you-drove-me-to-it

Closed
as Deferred Help for as Deferred

1
0
Sign in
to vote
Type: Bug
ID: 777768
Opened: 1/29/2013 7:57:25 AM
Access Restriction: Public
1
Workaround(s)
0
User(s) can reproduce this bug
Creating a unique_ptr and passing it into a function/method causes the linker errors:

error LNK2028: unresolved token (0A00007C) "private: __thiscall std::unique_ptr<int,struct std::default_delete<int> >::unique_ptr<int,struct std::default_delete<int> >(class std::unique_ptr<int,struct std::default_delete<int> > const &)" (??0?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FAAE@ABV01@@Z) referenced in function "public: static void __clrcall std::unique_ptr<int,struct std::default_delete<int> >::<MarshalCopy>(class std::unique_ptr<int,struct std::default_delete<int> > *,class std::unique_ptr<int,struct std::default_delete<int> > *)" (?<MarshalCopy>@?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FSMXPAV12@0@Z)

error LNK2019: unresolved external symbol "private: __thiscall std::unique_ptr<int,struct std::default_delete<int> >::unique_ptr<int,struct std::default_delete<int> >(class std::unique_ptr<int,struct std::default_delete<int> > const &)" (??0?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FAAE@ABV01@@Z) referenced in function "public: static void __clrcall std::unique_ptr<int,struct std::default_delete<int> >::<MarshalCopy>(class std::unique_ptr<int,struct std::default_delete<int> > *,class std::unique_ptr<int,struct std::default_delete<int> > *)" (?<MarshalCopy>@?$unique_ptr@HU?$default_delete@H@std@@@std@@$$FSMXPAV12@0@Z)


This does not occur in my example project in a normal non-CLI build. These errors are from Visual Studio 2010, but I have tested in Visual Studio 2012 express, and the same errors occur. I have tried using pragma managed on/off and only using the unique_ptr's in the unmanaged functions, without success.
Details (expand)

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

Visual Studio 2012

Steps to reproduce

1. Create a C++/CLI console application
2. Use the simple test case:

#include "stdafx.h"
#include <memory>

using namespace System;

void imALittleFunction(std::unique_ptr<int> value)
{
}

int main(array<System::String ^> ^args)
{
    imALittleFunction(std::unique_ptr<int>(new int(10)));

    return 0;
}

Product Language

English

Operating System

Windows 7 SP1

Operating System Language

English

Actual results

Errors given in description.

Expected results

No errors.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/12/2013 at 1:50 PM
Hi,

Thank you for taking the time to provide your feedback. After reviewing your reported issue, in the context of all the issues reported to us, we have decided not to take any action on this feedback at this time. We will re-consider our decision for a future release.

If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com or call 1-800-MICROSOFT for assistance.
For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

Thanks,
Karl Niu
VC++ Team
Posted by you-drove-me-to-it on 1/30/2013 at 2:36 AM
Regarding the workaround posted by Viorel_, I don't think this would really work in my case, because it changes the point that the memory is freed, and I discovered the problem by including a template that uses this behaviour to have memory freed at the end of a method, when it no longer needs some temporary memory held by a class member variable. The example I made is the simplest case I could come up with, and reworking the templates to manually delete the memory would be a considerable amount of work, and somewhat defeats the purpose of unique_ptr.
Posted by Microsoft on 1/29/2013 at 6:12 PM
Thanks for your feedback.

We are rerouting 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.
Posted by Microsoft on 1/29/2013 at 8:50 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 Viorel_ on 1/30/2013 at 1:47 AM
Try this workaround:

void imALittleFunction( std::unique_ptr<int> && value )
{
}