Home Dashboard Directory Help
Search

std::make_shared needs default constructor to compile by jensa79


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 716995
Opened: 1/6/2012 12:06:26 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Hi,

I tried to use std::make_shared with a class that does only have a user-defined constructor and no default constructor. The compiler reports an error when I try to compile this:

#include <memory>
#include <utility>

struct A
{
A(int) {}
A(A&& a) {}
private:
// uncomment next line to make it work
// A() {}
A(A const&); // not needed, jsut to make sure that it isn't accessed
};

void f()
{
A b(1);
std::shared_ptr<A> a = std::make_shared<A>( std::move(b) );
}

When you declare the default constructor, the compiler does not have a problem and even links it although there is no definition available. I double-checked with gcc 4.6 and this compiler does not report any error.

It turns out that the problem only occurs when I use the compiler switch to turn some warnings into errors. I have prepared a complete project which reproduces the problem. If you remove the warnings in the advanced properties from the option "Treat some warning as errors", everything works fine.

Best regards,
Jens
Details
Sign in to post a comment.
Posted by jensa79 on 5/31/2012 at 12:49 AM
Hi Stephan,

too bad that we will not be able to use VS11 because we need to target Windows XP. We develop for XP embedded for our devices, and XP embedded is still supported for a long time. I just stumbled over another bug with std::ref, it seems that VS10 has more and more problems popping up when we use the newer C++ features. Will there be patches or bugfixing releases for developers who have to stick to VS10? Or is "eat VS11 or die" the official direction MS is taking?

Best regards,
Jens
Posted by Microsoft on 3/23/2012 at 8:18 PM
Hi,

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11.

As a workaround, if you don't turn warning C4610 into an error, this code will compile cleanly. (On the commandline, this is the difference between /W4 /we4610 and /W4 /WX. It appears that /we4610 bypasses the STL's usual warning-suppression guards, which is why we didn't notice this earlier - we ensure that all of our tests build cleanly at /W4 /WX.)

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by jensa79 on 2/16/2012 at 12:40 AM
Hi,

any progress on this? It starts popping up more frequently at our team because we are using std::make_shared more and it is quite annoying.
Posted by Microsoft on 1/13/2012 at 2:13 AM
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 jensa79 on 1/10/2012 at 6:18 AM
After a little more investigation I found out that our project settings to treat some warnings as errors produce the problem. I've attached a complete project to reproduce the problem.
Posted by jensa79 on 1/10/2012 at 6:01 AM
Sorry, I was in a hurry when I posted this. I've fixed the type in the comment and also added compiler output with the actual error message.
Posted by MS-Moderator10 [Feedback Moderator] on 1/6/2012 at 1:13 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Unfortunately, we are unable to reproduce the issue with the steps you provided. Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by MS-Moderator01 on 1/6/2012 at 12:43 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 jensa79 on 1/10/2012 at 6:02 AM
Declare default constructor in class. Even when the constructor is not defined, the program links without problems.
File Name Submitted By Submitted On File Size  
make_shared.zip 1/10/2012 4.53 MB