title: Why doesn't make_shared work with Variable Length Arrays?
body: <p>consider the following: I have a class A with a constructor which takes an array of ints of size 3 as argument.</p>
  
  <p>Now I want to construct a shared_ptr to A. If I use </p>
  
  <p><code>shared_ptr&lt;&gt;(new A (parameter))</code></p>
  
  <p>everything is fine.</p>
  
  <p>But if I try using </p>
  
  <p><code>make_shared&lt;A&gt;(parameter)</code></p>
  
  <p>the compiler gives an error message. This happens only if the parameter-array is declared on the stack AND with a variable as array size (int parameter [n])</p>
  
  <p>The problem disappears when using static arrays (int parameter[3]) or allocating the array on the heap with new.</p>
  
  <p>I mean, this is no serious issue as there are the mentioned workarounds. Still, I would appreciate any explanation on why whis happens...</p>
  
  <p>Btw I'm using g++ 4.8.2.</p>
  
  <p>Here is a minimal example and the error log:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  using namespace std;
  
  // some simple class
  class A
  {
  public:
      A () {};
      A (int var[3]) {}; // some non-default constructor with an array as argument
      void foo (){cout &lt;&lt; "foo()" &lt;&lt; endl;};
  };
  
  int main()
  {
      // make a shared_ptr to A
      shared_ptr&lt;A&gt; ptr;
  
      // allocate an array var1 of size nVars=3 on the stack
      int nVars = 3;
      int var1[nVars];
      ptr = shared_ptr&lt;A&gt; (new A(var1)); // without make_shared, the c'tor is recognized
      ptr-&gt;foo();
      ptr = make_shared&lt;A&gt; (var1); // &lt;- error at compile time!
      ptr-&gt;foo();
  
      // same with static array var2 of size 3
      int var2[3];
      ptr = make_shared&lt;A&gt; (var2); // &lt;- no compilation error
      ptr-&gt;foo();
  
      // same with dynamic array var3 of size 3
      int* var3 = new int[nVars];
      ptr = make_shared&lt;A&gt; (var3); // &lt;- no compilation error
      ptr-&gt;foo();
  
      return 0;
  }
  </code></pre>
  
  <p>build log:</p>
  
  <pre><code>g++ -std=c++0x -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
  ../main.cpp: In function ‘int main()’:
  ../main.cpp:25:28: error: no matching function for call to ‘make_shared(int [(((sizetype)(((ssizetype)nVars) + -1)) + 1)])’
    ptr = make_shared&lt;A&gt; (var1); // &lt;- error at compile time!
                              ^
  ../main.cpp:25:28: note: candidate is:
  In file included from /usr/include/c++/4.8/memory:82:0,
                   from ../main.cpp:2:
  /usr/include/c++/4.8/bits/shared_ptr.h:610:5: note: template&lt;class _Tp, class ... _Args&gt; std::shared_ptr&lt;_Tp1&gt; std::make_shared(_Args&amp;&amp; ...)
       make_shared(_Args&amp;&amp;... __args)
       ^
  /usr/include/c++/4.8/bits/shared_ptr.h:610:5: note:   template argument deduction/substitution failed:
  ../main.cpp:25:28: note:   variable-sized array type ‘int (&amp;)[(((sizetype)(((ssizetype)nVars) + -1)) + 1)]’ is not a valid template argument
    ptr = make_shared&lt;A&gt; (var1); // &lt;- error at compile time!
                              ^
  </code></pre>
  
  <p>Cheers and thanks in advance for your answers!</p>
  
  <p>Juri</p>