Is g++ different than g++ -std=c++14 when the default standard is 201402L (c++14)?

926 Views Asked by At

I was trying to make use of precompiled headers to speed up compilation following this link: https://codeforces.com/blog/entry/53909

I observed that pre-compilation of headers and subsequent compilation of .cpp programs have to be done using the same g++ flags for the speed-up to work, which makes sense. However, explicitly setting the c++ standard to the default one did not work. So, neither of pre-compilation using g++ stdc++.h and subsequent g++ -std=c++14 program.cpp, nor, g++ -std=c++14 and g++ program.cpp worked.

This didn't make sense to me as I knew that my compiler, x86_64-w64-mingw32-g++.exe (gcc version 10.2.0), by default, conforms to 201402L (c++14) standard, which I figured using g++ -dM -E -x c++ /dev/null | fgrep __cplusplus, and getting the following response:

#define __cplusplus 201402L

So, my question is, what is the difference between g++ and g++ -std=c++14 when g++, by default, adheres to 201402L? Also, is it significant enough for me to specifically opt for either one of them ?

1

There are 1 best solutions below

1
On BEST ANSWER

GCC doesn't compile with -std=c++14 by default. The description of the -std flag from the GCC man pages (for version 9.3.0) says

-std= Determine the language standard. This option is currently only supported when compiling C or C++.

The compiler can accept several base standards, such as c90 or c++98, and GNU dialects of those standards, such as gnu90 or gnu++98. When a base standard is specified, the compiler accepts all programs following that standard plus those using GNU extensions that do not contradict it.
. . .
A value for this option must be provided; possible values are
. . .
c++14
c++1y
    The 2014 ISO C++ standard plus amendments. The name c++1y is deprecated.

gnu++14
gnu++1y
    GNU dialect of -std=c++14. This is the default for C++ code. The name gnu++1y is deprecated.
. . .

Emphasis mine. The current default is -std=gnu++14, which targets the C++14 standard while also enabling GNU extensions to the C++ language. The distinction between the -std=c++XX flags and the -std=gnu++XX flags is explained further in What are the differences between -std=c++11 and -std=gnu++11?.