vittorioromeo / Tutorials

Repository for my YouTube tutorials + code snippets
https://www.youtube.com/channel/UC1XihgHdkNOQd5IBHnIZWbA
Other
231 stars 54 forks source link

Invalid narrowing in C++14 example #3

Closed hacst closed 9 years ago

hacst commented 9 years ago

Hi. While watching one of your C++14 videos (those are nicely produced btw.) I noticed one of your examples narrowing a double to int (https://github.com/SuperV1234/Tutorials/blob/master/DiveIntoC%2B%2B14/1_CPP14/p4.cpp#L23). This is not allowed by the standard.

With clang 3.6 I get:

p4.cpp:19:28: error: type 'double' cannot be narrowed to 'int' in initializer
      list [-Wc++11-narrowing]
        template<typename T> T pi{3.14159265359};
                                  ^~~~~~~~~~~~~
vittorioromeo commented 9 years ago

Thanks for reporting this mistake, I can reproduce it. Sorry for the incorrect piece of code!

I commented the wrong line and added a note in p4.cpp.