I understand that experimental features of a programming language should not be enabled by default so I welcome the flags -std=c++0x
and -std=c++1y
. However C++11 is now standard since a couple of years. Why compilers still require -std=c++11
to enable the support for its features?

- 228,013
- 71
- 433
- 510

- 5,377
- 1
- 33
- 52
-
7You might want to take a look at [breaking changes introduced by C++11](http://stackoverflow.com/questions/6399615/what-breaking-changes-are-introduced-in-c11). – Qantas 94 Heavy Dec 04 '13 at 11:06
-
1Relevant? http://nuwen.net/mingw.html ("I've changed GCC's default mode to C++11.") – R. Martinho Fernandes Dec 04 '13 at 11:08
-
1This question appears to be off-topic because it is about marketing and product packaging, not computer programming. – user207421 Dec 04 '13 at 11:10
-
1As Qantas implies, a program that compiles in `c++03` will not necessarily compile in `c++11`. Typically if you want a newer version of gcc, you want to install it locally to avoid problems with libraries, the distro's default compiler, etc. – Dec 04 '13 at 11:18
-
@R.MartinhoFernandes IIUC, that link only concerns the Mingw distribution of g++, not g++ in general. – James Kanze Dec 04 '13 at 11:24
-
3@EJP: it's about how to make a backward-incompatible change to a highly-used software component. Personally, I do not let the marketing department do that on their own, but YMMV ;-p – Steve Jessop Dec 04 '13 at 11:25
-
@JamesKanze I know. But it seems to provide something the OP might be interested in. – R. Martinho Fernandes Dec 04 '13 at 11:29
-
@EJP The attempt to narrow the scope too much will only lead to folk using other forums. – Bathsheba Dec 04 '13 at 11:39
-
@JamesKanze oh, and to be correct, it only concerns *that* particular MinGW distribution. The official MinGW packages still default to gnu++03 or whatever it is. – R. Martinho Fernandes Dec 04 '13 at 11:40
-
7 question upvotes, 12 answer votes (congratulations on the silver enlightened medal) yet 3 close votes. Should this question ever be closed? See http://meta.stackexchange.com/questions/209883/disallow-closing-of-questions-with-a-certain-number-of-question-answer-upvotes – Bathsheba Dec 04 '13 at 12:06
-
@Qantas94Heavy If you want to use a 10 years old standard, then use a 10 years old compiler (or so). I don't see the point for new compilers to hidden new standard features behind a flag. – DarioP Dec 04 '13 at 13:26
-
5@DarioP I don't disagree with your comment, but note: by default `g++` doesn't use exactly the `c++98` mode (or `c++03`, both actually mean C++2003) but rather `gnu++98` ([source](http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html)), which adds some non-standard extensions; that's why I have always specified the Standard to use explicitly, with either `-std=c++98`/`-std=c++03` or `-std=c++11` (and enforced it with `-pedantic-errors`). So whatever C++98/03 or C++11, I always need to use a flag anyway (at least for portable code) :) (That's for GCC & Clang; MSVC doesn't let you choose.) – gx_ Dec 04 '13 at 13:54
-
@DarioP Two reasons: the first is that they aren't necessarily stable yet, and are far more likely to contain bugs, so you must explicitly say that you'll take the risk. The second is that new features break existing code, and as a compiler writer, you want to provide a transition path: only old; old, but option for new; new but option for old; and maybe, in about twenty years time, only new. – James Kanze Dec 04 '13 at 14:14
-
@gx_ that's actually a good point for those compilers! – DarioP Dec 04 '13 at 14:20
2 Answers
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.
Basically, lots of people (and makefiles) rely on the compiler being a conforming C++03 compiler, or at least on its non-conformance being known. Since C++11 introduces new instances of non-conformance with C++03, the change is potentially traumatic.
Arguably anyone relying on C++03 should have specified an option to say so, and changes to the default mode would make no difference to them. But once you've documented your compiler's default, people are going to rely that, either intentionally or otherwise.
For gcc in particular, the 4.8.2 man page says that "support for C++11 is still experimental". So I think ultimately the answer to your question may be that it takes more than 2 years to properly implement C++11, even starting from all the work done with draft standards.

- 273,490
- 39
- 460
- 699
-
With regards to the first point: it should be "complete and stable". There's a certain lapse of time between the first implementation of something, and real stability. – James Kanze Dec 04 '13 at 11:19
-
@JamesKanze: agreed that's highly desirable, and a responsible compiler implementer isn't going to ship something with unstable default mode. I'm not really sure what to define as "absolute minimum". For quality reasons it should be stable, whereas being complete is part of the definition of `-std=c++11` :-) – Steve Jessop Dec 04 '13 at 11:22
-
+1 for "traumatic" (of course the rest is ok too ;) ). Probably best description of the effect on some few "C++ projects" I've seen that still used pre-03 language. And hardly used boost or stl.. – quetzalcoatl Dec 04 '13 at 11:27
-
7It's basically a judgement call on the part of the compiler vendor. An awful lot of vendors claimed C++98, then C++03 without ever implementing `export`. And different vendors have different standards for stability, as well (and their standards vary---I can remember when g++ was releasing a new version every day, whereas today, they seem to be one of the stricter "vendors"). – James Kanze Dec 04 '13 at 11:27
-
1@JamesKanze: yes, `export` was one of the specific things I was thinking about when I said "non-conformance being known". It's a *lot* easier to deal with a missing feature that was never there, than something that suddenly stops working. Or even on something that suddenly starts working, like 2-phase lookup. – Steve Jessop Dec 04 '13 at 11:28
-
to rely on a "default behaviour" is almost always a really bad idea in the programming world, don't get used to the idea of "default", when you write a makefile or you build something, always go for the complete set of options that fulfill your requirements. – user2485710 Dec 04 '13 at 11:38
-
@SteveJessop my suggestion was more for the programmers that are writing C++ code than compiler-writers, in other words, a "makefile" without explicit arguments for the compiler is almost always a source for troubles . – user2485710 Dec 04 '13 at 11:48
-
@user2485710: While true, the reality is that people do not do this. – Lightness Races in Orbit Dec 04 '13 at 12:10
-
@user2485710: I meant that compiler-writers don't take the attitude that their users do what you suggest. Hence (I claim) they're cautious about breaking changes to the default mode. – Steve Jessop Dec 04 '13 at 12:59
-
3@RaydelMiranda: not on my system. `echo __cplusplus > version.cpp; g++ -E version.cpp` outputs `199711L`, whereas `g++ -std=c++11 -E version.cpp` outputs `201103L`. That's gcc 4.8.2. – Steve Jessop Dec 05 '13 at 00:21