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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to