0

My g++ version is Ubuntu 5.4.0:

    g++ --version
    g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12)

From the man page, I see this:

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

       gnu++14
       gnu++1y
           GNU dialect of -std=c++14.  The name gnu++1y is deprecated.

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

Does that mean "-std=c++1z" for c++17? I am confused what should be used for c++17 because some programs just use "-std=c++17" directly and compiled successfully using this g++.

visitor99999
  • 163
  • 1
  • 10
  • Isn't this something you can answer yourself just by trying it? The compiler should tell you if it's a valid option or not, so you can try `-std=c++17` and see if you get an error message. – Ken White May 22 '21 at 01:11
  • right, my question sounded a weird one. I did try -std=c++17 for some code but it failed when using "inline static" feature in c++17. But some other installations using -std=c++17 with this g++ worked just fine. So that's why I am confused – visitor99999 May 22 '21 at 01:22
  • I don't think your version of G++ is current enough. See https://stackoverflow.com/a/48312534/62576 and https://gcc.gnu.org/projects/cxx-status.html – Ken White May 22 '21 at 01:38
  • Thanks. The first link says this g++ has limited c++17 support so that may explain why some code worked while other didn't. Do you happen to know how to upgrade g++ in Ubuntu 16.04? – visitor99999 May 22 '21 at 02:01
  • Umm... At gcc.gnu.org? – Ken White May 22 '21 at 02:09
  • I was thinking do a "sudo apt-upgrade...". But seemed many variants doing this and don't want to mess up current system – visitor99999 May 22 '21 at 02:13
  • You should ask how to do this upgrade on [ubuntu.se]. – Ken White May 22 '21 at 02:19
  • I used these 3 steps upgrade from 5.4.0 to gcc/g++8: sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install gcc-8 g++-8. These 3 steps worked and c++17 is already the default version. No need to specify -std=c++17 anymore – visitor99999 May 23 '21 at 00:52

1 Answers1

0

These 3 steps can update Ubuntu gcc/g++ from default 5.4.0 to 8:

  1. sudo add-apt-repository ppa:ubuntu-toolchain-r/test
  2. sudo apt-get update
  3. sudo apt-get install gcc-8 g++-8
visitor99999
  • 163
  • 1
  • 10