This is definitely a bug in the Microsoft compiler.
Here is one big difference in C and C ++.
e0 ? e1 : e2
In C ++, the condtional expression expresses an lvalue, if at least one of the expressions in the second part (after '?' ) Is an rvalue, and in C, a conditional expression always produces an rvalue, no matter what. This means the following code is great for C ++, but this is a bug in C:
int a=10, b=20; (a<b?a:b) = 100;
In C ++, this will not give any error, precisely because the expression (a<b?a:b) is an lvalue expression, since you can put it on the left side of the job.
Now back to the original question. In your case, a and b are arrays of type char (&) [6] , and the expression a<b? a : b a<b? a : b should generate an lvalue, since there is no need to convert the array to a pointer. But in the Microsoft compiler it seems like converting an array to a pointer.
To test this, you can write this:
template <typename T, int N> inline void f(T const (&a)[N]) {} template <typename T> inline T const& compare (T const& a, T const& b) { f(a < b ? b : a);
And it gives no error (in GCC), which means that the expression you pass to f() is an array, not a pointer.
Nawaz
source share