When will Gnu C++ support C++11 without explicitly asking for it?

时光毁灭记忆、已成空白 提交于 2019-11-26 09:46:49

问题


Currently, with g++-4.8.1 you have to compile a file in C++11-mode via

g++ -std=c++11 -o prog.x prog.cpp

Is there a plan when I just can say

g++ -o prog.x prog.cpp

to compile prog.cpp?

Maybe prog.cpp has

  • #include <regex>
  • thread_local
  • class Widget { int member = 5; }
  • MyType operator\"\" myt(const char*, sze_t);
  • and so on.

回答1:


GCC 6.0: https://gcc.gnu.org/gcc-6/changes.html

The default mode for C++ is now -std=gnu++14 instead of -std=gnu++98.




回答2:


The closest I think to an answer I can get is from the info gcc command:

A revised ISO C++ standard was published in 2011 as ISO/IEC 14882:2011, and is referred to as C++11; before its publication it was commonly referred to as C++0x. C++11 contains several changes to the C++ language, most of which have been implemented in an experimental C++11 mode in GCC. For information regarding the C++11 features available in the experimental C++11 mode, see http://gcc.gnu.org/projects/cxx0x.html. To select this standard in GCC, use the option '-std=c++11'; to obtain all the diagnostics required by the standard, you should also specify '-pedantic' (or '-pedantic-errors' if you want them to be errors rather than warnings).

The http://gcc.gnu.org/projects/cxx0x.html page says:

Important: GCC's support for C++11 is still experimental. Some features were implemented based on early proposals, and no attempt will be made to maintain backward compatibility when they are updated to match the final C++11 standard.

The libstdc++ page also shows that it is incomplete. (I don't even think regex is implemented yet.)

Steve Jessop's answer basically says the same thing in the last paragraph, but to quote the first part of his answer:

C++11 has been standard for a couple of years, but a compiler isn't going to switch its default mode to C++11 until:

  • At an absolute minimum, C++11 support is complete in that compiler and the libraries it uses. And also stable, if the compiler writer has any concern at all for reliability.
  • Preferably, a major version number increase in the compiler, since C++11 is not fully backward-compatible to C++03.
  • Ideally, on a well-known schedule so that users can prepare for the change.



回答3:


UPDATE: The original answer has become outdated in the past 28 months. According to nobar's answer, GCC 6.1 supports C++14 with GNU extensions by default. GCC 6.1 was released on April 27, 2016. I am quite surprised but very happy to see such a fast adoption of the new standard!

As for the rest of the original answer, I still see value in keeping that part that answers how to make certain flags "default". So I kept it below.


Is there a plan when I just can say [...]

You could define default flags in a Makefile and then all you have to say is make.

The accepted answer to How do I enable C++11 in gcc? should get you started (or some makefile tutorial).

Another advice that seems to pop up often here at Stackoverflow is to add a bash alias alias g++="g++ --std=c++0x", see here how. However, I personally wouldn't do this though, it can lead to unpleasant surprises; there has been breaking changes with C++11. I would create my own makefile and type simply make.





回答4:


It seems GCC 5.0 will have gnu11 (dialect of c++11 AFAIK) by default with improvements to c++11 as being shared in changes. See https://gcc.gnu.org/gcc-5/changes.html . It seems it will have some support for C++14 as well.

One of the more interesting statements as far as regards to the bugzilla scenario as shared by @marc-glisse seems to be off the table, see https://gcc.gnu.org/gcc-5/criteria.html for details :-

All regressions open in Bugzilla have been analyzed, and all are deemed as either unlikely to affect most users, or are determined to have a minimal impact on affected users. For example, a typographical error in a diagnostic might be relatively common, but also has minimal impact on users.

In general, regressions where the compiler generates incorrect code, or refuses to compile a valid program, will be considered to be sufficiently severe to block the release, unless there are substantial mitigating factors. - GCC release criteria page

The timeline does give some idea as to when and if it will happen https://gcc.gnu.org/develop.html#timeline

So hopefully we should see a new gcc with c++11 support as default by 2015. When will GNU/Linux distributions take up and do whatever they need to do for softwares being built with c++11 is another question altogether.



来源:https://stackoverflow.com/questions/21221411/when-will-gnu-c-support-c11-without-explicitly-asking-for-it

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