63

I'm using g++ 4.8.4 on Ubuntu 14.04 LTS. When trying to compile with '-std=c++14', I get this error:

g++: error unrecognized command line option '-std=c++14'

Compiling with '-std=c++11' works fine, so I'm not sure what's going on. Does g++ really have no support for c++14 yet? Am I using a wrong command line option?

I used "sudo apt-get install g++" which should automatically retrieve the latest version, is that correct?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Silverlan
  • 2,783
  • 3
  • 31
  • 66

4 Answers4

71

For gcc 4.8.4 you need to use -std=c++1y in later versions, looks like starting with 5.2 you can use -std=c++14.

If we look at the gcc online documents we can find the manuals for each version of gcc and we can see by going to Dialect options for 4.9.3 under the GCC 4.9.3 manual it says:

‘c++1y’

The next revision of the ISO C++ standard, tentatively planned for 2014. Support is highly experimental, and will almost certainly change in incompatible ways in future releases.

So up till 4.9.3 you had to use -std=c++1y while the gcc 5.2 options say:

‘c++14’ ‘c++1y’

The 2014 ISO C++ standard plus amendments. The name ‘c++1y’ is deprecated.

It is not clear to me why this is listed under Options Controlling C Dialect but that is how the documents are currently organized.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • Note that in gcc 4.8, this only adds support for return type deduction for normal functions. Many other features were not added until 4.9 or 5, as elaborated [here](https://gcc.gnu.org/projects/cxx-status.html#cxx14). – skoush Aug 03 '18 at 18:02
21

The -std=c++14 flag is not supported on GCC 4.8. If you want to use C++14 features you need to compile with -std=c++1y. Using godbolt.org it appears that the earilest version to support -std=c++14 is GCC 4.9.0 or Clang 3.5.0

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
5

G++ does support C++14 both via -std=c++14 and -std=c++1y. The latter was the common name for the standard before it was known in which year it would be released. In older versions (including yours) only the latter is accepted as the release year wasn't known yet when those versions were released.

I used "sudo apt-get install g++" which should automatically retrieve the latest version, is that correct?

It installs the latest version available in the Ubuntu repositories, not the latest version that exists.

The latest GCC version is 5.2.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • 1
    `I used "sudo apt-get install g++" which should automatically retrieve the latest version, is that correct?` It installs the latest _point release_ of _whichever major release_ the Ubuntu/Debian repositories have chosen to consider as the _default_, unqualified version. Often multiple packages are available for different, including newer, major versions - in which case, we have to explicitly specify that we want a non-default major release, e.g. `sudo aptitude install g++-6` as I recently had to do on Debian unstable. The default there just now, in the package just named `g++`, is version 5.x. – underscore_d Aug 20 '16 at 07:18
2

Follow the instructions at https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91 to set up the gcc version you need - gcc 5 or gcc 6 - on Ubuntu 14.04. The instructions include configuring update-alternatives to allow you to switch between versions as you need to.

WillC
  • 957
  • 16
  • 19
  • ( Note to whoever might want to comment "Answer with code not a link": https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91 is application2000's work, not mine, so I'm in no position to claim that it's my answer. But I can show people where to get more useful instructions than the 5 separate stackoverflow questions I waded through. ) – WillC Nov 04 '18 at 09:20