vendredi 6 mars 2015

clang++ 2d array pointer weird errors

The following code compiles fine with g++, but fails with clang++ in c++11 mode. I have noted the errors inline. Can some one explain exactly what the problem is? It seems that it has to do with difference between lvalue and rvalue.



#include <iostream>
using namespace std;
int main(){
int nx=1000;
int ny=1000;
double *p=new double[nx*ny];
auto pp=(double (*)[nx])p;//fine
auto pp2=(double (*)[nx])p;//fine
pp=pp2; //error: assigning to 'double (*)[nx]' from incompatible type 'double (*)[nx]'
decltype(pp2) pp3=pp2;//fine
double (*pp4)[nx]=(double(*)[nx])p;//error: cannot initialize a variable of type 'double (*)[nx]' with an rvalue of type 'double (*)[nx]'
double (*pp5)[nx]=pp;//error: cannot initialize a variable of type 'double (*)[nx]' with an lvalue of type 'double (*)[nx]'
pp=pp2;//error: assigning to 'double (*)[nx]' from incompatible type 'double (*)[nx]'
pp=(double(*)[nx])p;//error: assigning to 'double (*)[nx]' from incompatible type 'double (*)[nx]'
pp[1][0]=1;
cout << pp2[1][0]<< endl;
}

Aucun commentaire:

Enregistrer un commentaire