[LLVMbugs] [Bug 23976] New: Cast linear array to rectangular array compilation failure
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sat Jun 27 16:54:57 PDT 2015
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: unassignedclangbugs at nondot.org
Reporter: jhart.public at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150627/492b18fd/attachment.html>
More information about the llvm-bugs
mailing list