{} narrowing?

Category: visual studio vclanguage

Question

Itpai on Fri, 07 Jun 2013 23:26:06


I get the following warnings:

warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data

from this code:

int MyNumb2 = 4.5f;    // Get warning as expected.
int MyNumber = {4.5f}; // Get warning, should I get an error here?

Warning from line 1 is OK, but line 2 should not the {} initializer prevent narrowing and give me a compiler error?

Using Visual Studio 2012 Express desktop. Version 11.0.60315.01 Update 2.

Replies

Igor Tandetnik on Fri, 07 Jun 2013 23:34:36


On 6/7/2013 7:26 PM, Lars-Inge Tønnessen wrote:

Warning from line 1 is OK, but line 2 should not the {} initializer prevent narrowing and give me a compiler error?

http://connect.microsoft.com/VisualStudio/feedback/details/779993/vs2012-update-1-c-compiler-allows-built-in-type-narrowing-with-list-initialization


Igor Tandetnik