<html>
    <head>
      <base href="http://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 --- - clang incorrectly infers that a fixed length array is a VLA when passing a const size through a function."
   href="http://llvm.org/bugs/show_bug.cgi?id=20630">20630</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang incorrectly infers that a fixed length array is a VLA when passing a const size through a function.
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ian.forbes@mail.mcgill.ca
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang allows C-style arrays of non-POD type but only when the size of these
array is known at compile time as per:
<a href="http://clang.llvm.org/compatibility.html#vla">http://clang.llvm.org/compatibility.html#vla</a>

However the following does not complile and complains that the array has a
variable length.

========================================

#include <vector>                                                               

void func(const int n)                                                          
{                                                                               
    std::vector<int> futs[n];                                                   
}                                                                               

int main()                                                                      
{                                                                               
    const int n = 5;                                                            
    func(n);                                                                    
}

========================================

works2.cpp:5:26: error: variable length array of non-POD element type
'std::vector<int>'
    std::vector<int> futs[n];
                         ^
1 error generated.

=========================================

This also happens when calling func with a literal.

The issue is that the size of the array is known at compile time but clang does
not know this unless the size is in the local scope of the function when the
array is being created.

This may not actually be a bug and may be the expected behaviour but if this is
the case the webpage should be updated to reflect this short comming. 

Additional Info:

Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix</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>