1

The following code compiles using Xcode 6.3.2 but not Visual Studio 2013.

#include <cstdint>
#include <memory>

class Y
{
public:
    Y(uint32_t i) : m_i(i)
    {
    }

private:
    uint32_t m_i;
};

class X
{
public:
    X() = default;

private:
    const uint32_t m_dimension = 2;
    const std::shared_ptr<Y> m_y = std::make_shared<Y>(m_dimension);
};

The error reported is:

error C2783: 'std::shared_ptr<_Ty> std::make_shared(_Types &&...)' : could not deduce template argument for '_Ty'

Could this be a compiler bug in Visual Studio or is there something wrong with the code?

ksl
  • 4,519
  • 11
  • 65
  • 106
  • 1
    this code compiles without any error on Visual 2013 (Update 4). To generate this error I have to write `make_shared(` instead of `make_shared(` – Hcorg Jul 20 '15 at 15:56
  • It appears this bug has been [documented](https://connect.microsoft.com/VisualStudio/feedbackdetail/view/818825/torino-in-class-member-initialization-using-std-make-shared-type-fails-to-compile) – Alejandro Jul 20 '15 at 16:01
  • @Hcorg - Update 4? How do I find that information? I see only: Microsoft Visual Studio Express 2013 for Windows Desktop Version 12.0.21005.1 REL Microsoft .NET Framework Version 4.5.50938 – ksl Jul 20 '15 at 16:04
  • @ksl My 2013 Update 4 shows 12.0.31101.00 Update 4. But as of today, you can just jump to 2015! – Timbo Jul 20 '15 at 16:06
  • @Alejandro Thanks. Do you want to put that as an answer and I'll accept it? – ksl Jul 20 '15 at 16:08
  • @ksl if you don't see any "Update X" text, than you have old, not patched version - as Alejandro wrote - update 2013 or try 2015 – Hcorg Jul 20 '15 at 21:09

2 Answers2

2

It appears as though you're not the only one with this issue -- this bug has been documented! Newer versions of Visual Studio shouldn't have this issue (Update 4 of Visual Studio 2013 seems to be the starting point).

Alejandro
  • 3,040
  • 1
  • 21
  • 30
2

I had the same issue with VS2013 update 4 and have resolved it by updating it to version 5.