<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - VLA extension - explicit typing fails."
   href="https://llvm.org/bugs/show_bug.cgi?id=23149">23149</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>VLA extension - explicit typing fails.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sasho648@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The problem is that I can't assign VLA pointer or reference to a variable with
explicit type. Examples:

void func(std::size_t sz)
{
    int arr[sz];

    int (*pArr)[sz] = &arr;

    int (&refArr)[sz] = arr;
}

It fails to compile with those strange error message:

error: cannot initialize a variable of type 'int (*)[sz]' with an rvalue of
type 'int (*)[sz]'
    int (*pArr)[sz] = &arr;

error: non-const lvalue reference to type 'int [sz]' cannot bind to a value of
unrelated type 'int [sz]'
    int (&refArr)[sz] = arr;

On the other hand this works fine:

void func(std::size_t sz)
{
    int arr[sz];

    auto *pArr = &arr;

    auto &refArr = arr;
}

While reference to VLA arrays are not part of C99, pointers to them are
well-defined and should be supported if compatibility with this standard is
supported. However I hope reference will be kept too (as they are a cool
add-on).

Those constructs are well supported by GCC compiler too.


Life examples on online-compiler with Clang(3.7.0):

Non-working example:

<a href="http://melpon.org/wandbox/permlink/ZIUJrZqmvBmDzfkC">http://melpon.org/wandbox/permlink/ZIUJrZqmvBmDzfkC</a>

Working example, second one:

<a href="http://melpon.org/wandbox/permlink/gSXxvRXQRaCBzdwN">http://melpon.org/wandbox/permlink/gSXxvRXQRaCBzdwN</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>