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: unassignedclangb...@nondot.org
          Reporter: zhong...@pku.org.cn
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to