Why does GCC 6.3 compile this Braced-Init-List code without explicit C++11 support?

别来无恙 提交于 2019-12-21 03:52:44

问题


I have a question about the different meanings of a curly-brace enclosed list.

I know that C++03 did not support C++11's initializer_list. Yet, even without the -std=c++11 compiler flag, gcc 6.3 will properly initialize interpolate with this code:

map<string, string> interpolate = { { "F", "a && b && c" }, { "H", "p ^ 2 + w" }, { "K", "H > 10 || e < 5" }, { "J", "F && !K" } };

I was challenged on why this would work, and I realized I didn't have an answer. This is a Brace-Init-List, but the way we get from that to initializing a standard container is typically through an initializer_list. So how would non-C++11 code be accomplishing the initialization?


回答1:


The default compiler command for gcc 6.x is -std=gnu++14, so the compiler is implicitly compiling your code using a later version of the C++ language standard.

You will need to manually specify -std=c++03 if you want to compile in C++03.



来源:https://stackoverflow.com/questions/44654713/why-does-gcc-6-3-compile-this-braced-init-list-code-without-explicit-c11-suppo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!