46

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.
towi
  • 21,587
  • 28
  • 106
  • 187
  • 19
    This question appears to be off-topic because it is directed at the GNU C Compiler project. – Michael Foukarakis Jan 19 '14 at 19:23
  • 2
    Not for 4.9 at least. Maybe 4.10 (or 5.0), maybe later. – Marc Glisse Jan 19 '14 at 19:24
  • 2
    Defaulting to C++11 could potentially break some existing code. [This question](http://stackoverflow.com/questions/6399615/what-breaking-changes-are-introduced-in-c11) lists some of the changes that could cause a problem. – chbaker0 Jan 19 '14 at 19:27
  • 1
    I use 4.8.1 and I compile directly without having to pass `-std=c++11`. –  Jan 19 '14 at 19:28
  • @mebob I know. But the standardizers ver extra super special careful to make the incompatibilities visible at recompile. – towi Jan 19 '14 at 19:28
  • @BSH Then I gather you are not using any C++11 features – towi Jan 19 '14 at 19:29
  • @towi I just compiled a code with lambda and auto, compiled fine. –  Jan 19 '14 at 19:31
  • @towi Good point. I was just mentioning since it could be a little bit of a bother if you are trying to compile an existing project without being aware the compiler would default to the C++11 standard. Obviously, it would be an easy fix: `-std=c++03` for GCC. – chbaker0 Jan 19 '14 at 19:31
  • Probably right after they did something similar to the C compiler... – PlasmaHH Jan 19 '14 at 19:33
  • 3
    Related: [Why C++11 compiler support still requires a flag?](https://stackoverflow.com/questions/20373626/why-c11-compiler-support-still-requires-a-flag) Might even be a duplicate. –  Jan 19 '14 at 19:33
  • @mebob To be honest, when I scroll through the list I don't expect there is much bother with 99.998% projects. That's what they aimed for. The `auto` may be an issue with very oldish C/C++-code but the rest will be esoteric stuff and easy to fix -- the compiler will complain about most (`int final = 12`. Oh, wait, actually, that will compile, too, I think -- it's a context-keyword, isn't it?). – towi Jan 19 '14 at 19:35
  • @remyabel Oh, indeed. My question is Gnu C++-specific. But your point is well taken. The answer to that question is a bit more general, though. – towi Jan 19 '14 at 19:37
  • IMO the difference between this question and others is that others are asking why and this is asking when. Therefore I think it's off-topic because it boils down to speculation. –  Jan 19 '14 at 19:37
  • @remyabel ...or knowledge because it might have been discussed by the gnu c++ team. Thus, I do 'not complain too loudly if you decide its either. Although: For many questions here at SO you could just "write an Email to the authors" ;-) – towi Jan 19 '14 at 20:02
  • Quite agree with @mfukar. This is a good fit for [magic 8-ball](http://meta.stackexchange.com/q/1696/238706). :-) – Palec Jan 19 '14 at 20:12
  • @Palec You may be right. I leave the question closed, because it has been answered satisfactory for me. The correct Ouya-board-autocorrect would have been "Should my teaching slides for C++ students contain that they always have to add some special flag to the (gnu-)compiler or should I deliver that remark in the verbal channel only?" – towi Jan 20 '14 at 12:46
  • For long term maintainability you should *always* specify the language standard. This way your coders won't accidentally use a C++14 feature. Moving to a new standard becomes a conscious choice and you don't go back to compile on RHEL 6 and only then discover you need to rewrite big chunks. – Zan Lynx Oct 20 '15 at 15:40

4 Answers4

29

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.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
20

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.
Community
  • 1
  • 1
  • 7
    Regex is implemented in 4.9. The notion of "complete" support is vague. If they wait for bugzilla to be empty, they will never switch. – Marc Glisse Jan 19 '14 at 20:02
  • 1
    The same contents as in `info gcc` is available in online docs (page [Standards](http://gcc.gnu.org/onlinedocs/gcc/Standards.html)). For current status, see [C Dialect Options](http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html) – for C it states under gnu11: “GNU dialect of ISO C11. This is intended to become the default in a future release of GCC.” But for gnu++11 nor any other C++ dialect, there is no such remark. BTW probably gnu++11 will be a default sometime, not c++11. – Palec Jan 19 '14 at 20:05
  • @Marc Yep, it is implemented in the snapshot of gcc I have, but gcc 4.9 isn't released yet. –  Jan 19 '14 at 20:07
  • @MarcGlisse while it's missing classes, functions and entire header files, it's not "complete" by any measure. – Cubbi Jan 19 '14 at 20:49
13

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.


Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
-3

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.

shirish
  • 477
  • 1
  • 4
  • 12