Wrong result if function returns a float3 without explicit cast


couldn’t find an OpenCL forum, hopefully this is the right spot.

I got a somewhat longer function, which boils down to

inline float3 foo(void)
{ return((1,2,3)); }

Unexpectedly, this function returns (3,3,3) without any compiler warning. It works correctly if I change it like that:

inline float3 foo(void)
{ return((float3)(1,2,3)); }

Not sure if this is a bug or undefined behavior, hopefully it helps.
This was with the latest OpenCL Linux driver 319.17


OK, I dug a bit deeper. The source of the problem is that the OpenCL compiler does not display a warning for this ‘comma operator pitfall’ in the CL_PROGRAM_BUILD_LOG, but just eats it quietly. The usual warning in other compilers is “left-hand operand of comma expression has no effect” or so. Only if I compile with -Werror do I get an error (“expression result unused”). So the problem is detected, but for whatever reason no warning is displayed. Maybe this can be fixed.