[LLVMbugs] [Bug 23149] New: VLA extension - explicit typing fails.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Apr 7 09:10:02 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23149

            Bug ID: 23149
           Summary: VLA extension - explicit typing fails.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sasho648 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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:

http://melpon.org/wandbox/permlink/ZIUJrZqmvBmDzfkC

Working example, second one:

http://melpon.org/wandbox/permlink/gSXxvRXQRaCBzdwN

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150407/c47daf3e/attachment.html>


More information about the llvm-bugs mailing list