https://llvm.org/bugs/show_bug.cgi?id=23976
Bug ID: 23976
Summary: Cast linear array to rectangular array compilation
failure
Product: clang
Version: 3.5
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
Reinterpreting a dynamically allocated N*M block of int as an NxM rectangular
array fails with clang++ 3.5, producing a spurious error message:
test.cpp:5:8: error: non-const lvalue reference to type 'int [n][m]' cannot
bind to a value of unrelated type 'int [n][m]'
Code compiles successfully on the same platform with gcc 4.9.
test case:
#include <cassert>
void f(int *mem, int n, int m)
{
int (&array)[n][m] = *reinterpret_cast<int (*)[n][m]>(mem);
assert((void*)&array == (void*)mem);
assert(sizeof(array) == (n*m)*sizeof(int));
}
int main() {
const int N = 3;
const int M = 4;
int *p = new int[N*M];
f(p, N, M);
delete[] p;
}
clang++ -v output:
Debian clang version 3.5.2-1 (tags/RELEASE_352/final) (based on LLVM 3.5.2)
Target: x86_64-pc-linux-gnu
--
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