initialization - C++ curly brace delimited initializer lists -
i'm reading stroustrup's newest c++ book (4th edition) , following example book doesn't throw error.
#include <iostream> using namespace std; int main(const int argc, const char* argv[]) { // narrowing conversion. // according stroustrup, error should happen here // because curly-brace-delimited initializer // saves conversions lose information. // after compiling , running code output 7. int i2 {7.2}; cout << i2 << endl; return 0; } i'm using following command compile code on gentoo system. (g++ version: 4.6.3)
g++ -std=c++0x -o output input.cpp why doesn't throw error?
a more current version of gcc (4.8.1), treats warning:
trash9.cpp: in function 'int main(int, const char**)': trash9.cpp:11:14: warning: narrowing conversion of '7.2000000000000002e+0' 'double' 'int' inside { } [-wnarrowing] int i2 {7.2}; the standard requires compiler issue "diagnostic", (with right documentation) undoubtedly qualifies. compiler free continue compiling code afterwards.
vc++ closer apparently want:
trash9.cpp(11) : error c2397: conversion 'double' 'int' requires narro wing conversion
Comments
Post a Comment