Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 368
Jonathan Mee Avatar asked Jun 20 '17 13:06

Jonathan Mee


People also ask

Which version of GCC supports C++ 20?

GCC has experimental support for the latest revision of the C++ standard, which was published in 2020. C++20 features are available since GCC 8. To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line.

What can GCC compile?

GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++.

What is G ++ compiler?

GNU C++ Compiler ( g++ ) is a compiler in Linux which is used to compile C++ programs. It compiles both files with extension . c and . cpp as C++ files. The following is the compiler command to compile C++ program.


1 Answers

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.

like image 62
NathanOliver Avatar answered Sep 26 '22 03:09

NathanOliver