[llvm-bugs] [Bug 38350] New: cannot initialize a variable of type A with an rvalue of type A
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jul 28 18:06:10 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38350
Bug ID: 38350
Summary: cannot initialize a variable of type A with an rvalue
of type A
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: zhonghao at pku.org.cn
CC: llvm-bugs at lists.llvm.org
The code is as follow:
#include <iostream>
void test(const int *data, int dimension)
{
const int (*m)[dimension] = reinterpret_cast<const
int(*)[dimension]>(data);
for (int i = 0; i < dimension; ++i) {
for (int j = 0; j < dimension; ++j)
std::cout << m[i][j] << " ";
std::cout << std::endl;
}
}
int main()
{
int data[][2] = { {1, 2}, {3, 4} };
test(*data, 2);
return 0;
}
clang rejects the code:
error: cannot initialize a variable of type 'const int (*)[dimension]' with an
rvalue of type 'const int (*)[dimension]'
const int (*m)[dimension] = reinterpret_cast<const
int(*)[dimension]>(data);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
gcc accepts it.
My gcc is 9.0.0 and my clang is 7.0.0.
--
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/20180729/8d2b8830/attachment.html>
More information about the llvm-bugs
mailing list