Gnu C++ 何时会在不明确要求的情况下支持 C++11?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21221411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:33:06  来源:igfitidea点击:

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

c++gccc++11gcc4.8

提问by towi

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

目前,使用 g++-4.8.1,您必须通过以下方式以 C++11 模式编译文件

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?

编译prog.cpp

Maybe prog.cpphas

也许prog.cpp

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

采纳答案by nobar

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

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

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

C++ 的默认模式现在-std=gnu++14不是-std=gnu++98.

回答by nobar

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

我认为最接近我能得到的答案是来自info gcc命令:

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).

修订后的 ISO C++ 标准于 2011 年发布为 ISO/IEC 14882:2011,称为 C++11;在发布之前,它通常被称为 C++0x。C++11 包含对 C++ 语言的若干更改,其中大部分已在 GCC 中以实验性 C++11 模式实现。有关实验性 C++11 模式中可用的 C++11 功能的信息,请参阅 http://gcc.gnu.org/projects/cxx0x.html。要在 GCC 中选择此标准,请使用选项“-std=c++11”;要获得标准要求的所有诊断信息,您还应该指定“-pedantic”(如果您希望它们是错误而不是警告,则应指定“-pedantic-errors”)。

The http://gcc.gnu.org/projects/cxx0x.htmlpage says:

http://gcc.gnu.org/projects/cxx0x.html页说:

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.

重要提示:GCC 对 C++11 的支持仍处于试验阶段。一些功能是基于早期提案实现的,当它们更新以匹配最终的 C++11 标准时,不会尝试保持向后兼容性。

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

的libstdc ++页面还显示,这是不完整的。(我什至认为还没有regex实施。)

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

Steve Jessop 的回答在最后一段中基本上说了同样的话,但引用他回答的第一部分:

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.

C++11 已经成为标准已有几年了,但编译器不会将其默认模式切换到 C++11,直到:

  • 至少,该编译器及其使用的库中对 C++11 的支持是完整的。如果编译器编写者对可靠性有任何顾虑,那么它也是稳定的。
  • 最好在编译器中增加主要版本号,因为 C++11 并不完全向后兼容 C++03。
  • 理想情况下,按照众所周知的时间表,以便用户可以为更改做好准备。

回答by Ali

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!

更新:原始答案在过去 28 个月内已经过时。根据nobar 的回答,GCC 6.1 默认支持带有 GNU 扩展的 C++14。GCC 6.1 于 2016 年 4 月 27 日发布。我很惊讶但很高兴看到新标准的快速采用!

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.

您可以在 Makefile 中定义默认标志,然后您只需说make.

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

接受的答案如何使C ++在GCC 11?应该让你开始(或一些makefile 教程)。

Another advice that seems to pop up often here at Stackoverflow is to add a bash alias alias g++="g++ --std=c++0x", see herehow. 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.

Stackoverflow 上似乎经常出现的另一个建议是添加一个 bash 别名alias g++="g++ --std=c++0x",请参阅此处如何操作。但是,我个人不会这样做,它可能会导致不愉快的惊喜;C++11 发生了重大变化。我会创建自己的 makefile 并简单地输入make.



回答by shirish

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.

默认情况下,GCC 5.0 似乎将具有 gnu11(c++11 AFAIK 的方言),并在更改中共享对 c++11 的改进。请参阅https://gcc.gnu.org/gcc-5/changes.html。似乎它也会对 C++14 有一些支持。

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.htmlfor details :-

就@marc-glisse 共享的 bugzilla 场景而言,其中一项更有趣的陈述似乎不在讨论范围内,请参阅https://gcc.gnu.org/gcc-5/criteria.html了解详情:-

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

所有在 Bugzilla 中打开的回归都已经过分析,所有回归都被认为不太可能影响大多数用户,或者被确定对受影响用户的影响最小。例如,诊断中的印刷错误可能相对常见,但对用户的影响也很小。

一般来说,编译器生成不正确代码或拒绝编译有效程序的回归将被认为足够严重以阻止发布,除非有实质性的缓解因素。- GCC 发布标准页面

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

时间表确实提供了一些关于何时以及是否会发生的想法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.

所以希望我们应该在 2015 年看到一个默认支持 c++11 的新 gcc。 GNU/Linux 发行版什么时候会开始使用 c++11 构建软件,并为使用 c++11 构建的软件做任何他们需要做的事情,这完全是另一个问题。