C ++の入門書(5番目)では、次のように述べています。
組み込み型の変数で使用する場合、この形式の初期化には 1 つの 重要なプロパティがあります。初期化子が情報の損失につながる可能性がある場合、コンパイラは組み込み型の初期化変数をリストできません。
longdouble ld = 3.1415926536;
int a{ld}, b = {ld}; // error: narrowing conversion required
int c(ld), d = ld; // ok: but value will be truncate
gcc4.8.1 を使用してコードをコンパイルすると、エラーではなく警告のみが表示されます。
g++ -W -Wall -Wextra -pedantic -std=c++0x -o m main.cpp
main.cpp: In function ‘int main()’:
main.cpp:64:13: warning: narrowing conversion of ‘ld’ from ‘long double’ to ‘int’ inside { } [-Wnarrowing]
int a{ld}, b= {ld};
^
main.cpp:64:22: warning: narrowing conversion of ‘ld’ from ‘long double’ to ‘int’ inside { } [-Wnarrowing]
int a{ld}, b= {ld};
重要なプロパティの機能をオンにするフラグはありますか?