Question Re: 'auto' and error C4244

I was just curious about the ‘auto’ keyword and wether it will generate type conversion warnings such as C4244 “possible loss of data”. I searched google and read various articles about ‘auto’ but couldn’t find anything that addressed this.

Say for example I have this:

float x = 0.00f;
int y = 2;

auto z = x + y;

return z + 2.03f;

I didn’t see anything that mentioned any type precedence when determining the outcome. Obviously in the example above it’s important for Z to be a FLOAT so the return value doesn’t truncate.

In other words, these seem obvious:

auto z = int1 + int2 // z is an INT
auto z = float1 + float2 // z is a FLOAT
auto z = bool1 & bool2 // z is a BOOLEAN

but these don’t seem so obvious:

auto z = bool1 + int2 // z is a ? (assuming you’ve defined the + operator for boolean)
auto z = float1 + int2 // z is a ?
auto z = byte1 + int2 // z is a ?

So I’m curious does ‘auto’ tell the compiler use the datatype that holds the most data, or the datatype of the first variable on the line or does it scan the whole function looking at the context of Z and the function’s return value?

I understand ‘auto’ is primarily designed for complex definitions such as iterators and the like but I wonder how trustworthy it is in a basic sense such as the above. The examples on MSDN only show simple declarations and uses.

It’s all defined there in the standard document, http://ideone.com/PrzoVu

Float promotion and Int promotion

Thaks for that. I was just wondering if auto would actually stick to the rules.