The code here test for lvalue or rvalue after a type cast:
#include <stdio.h>
template <typename T>
T const f1(T const &t) {
printf("T const \n");
return t;
}
template <typename T>
T f1(T &t) {
printf("T\n");
return t;
}
struct KK {
int a;
};
int main()
{
KK kk;
kk.a=0;
int ii;
f1(kk);
f1((KK)kk);
f1(ii);
f1((int)ii);
return 0;
}
In gcc link the result is like this indicating rvalue resulted after a type cast:
T
T const
T
T const
But in VC++2010, this is the result indicating rvalue only if it is a class type:
T
T const
T
T
So is it a compiler bug or just some undefined behaviour when type cast to int?