Since which version of GCC is C++14 supported?

DBedrenko picture DBedrenko · Nov 14, 2017 · Viewed 12.5k times · Source

I was investigating why this piece of code compiles on my PC that has GCC v7.2, but doesn't compile with our toolchain's GCC v5.4, depsite -std=c++14 -Wpedantic -pedantic-errors being passed:

#include <array>
#include <vector>
#include <tuple>
typedef std::tuple<const char *, const char *, bool> StrStrBool;

const std::vector<StrStrBool> cApIDValidTestValues {
{
    {"str1", "str2", true },
    { "str3", "str4",  false }
}
};

The error is:

<source>:12:1: error: converting to 'std::tuple<const char*, const char*, bool>' from initializer list would use explicit constructor 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {const char (&)[5], const char (&)[5], bool}; <template-parameter-2-2> = void; _Elements = {const char*, const char*, bool}]' }; ^

This code is C++14 valid (explanation), so according to GCC's Standards Support page--which shows full C++14 support since GCC v5--I expected GCC v5.4 to be able to compile it.

But I was told online that it looks like the compiler of this GCC version supports C++14, but the accompanying libstdc++ is not C++14 compliant.

My related questions are:

  1. What is the earliest GCC version that provides a C++14 compliant libstdc++ ? How do I find this out for other standards too?
  2. Why would GCC advertise that it has C++14 support for a gcc version, but the libstdc++ shipped with it does not?
  3. Does this indicate the gcc compiler can be used with other stdlib implementations?

Answer

Jonathan Wakely picture Jonathan Wakely · Nov 14, 2017

This code is C++14 valid (explanation),

No it isn't (that "explanation" is completely unrelated).

so according to GCC's Standards Support page--which shows full C++14 support since GCC v5

That page clearly says "For information about the status of the library implementation, please see this page." However ...

--I expected GCC v5.4 to be able to compile it.

No, because 5.4 doesn't have C++17 support, and specifically doesn't have support for the "Improving pair and tuple" feature that was added to the draft C++ standard after C++14 was released. The feature was approved by the C++ committee at the May 2015 meeting, and GCC 5.1 was released in April 2015, and the changes for the feature are far too invasive to backport to a stable release branch of GCC. The library support page shows that libstdc++ supports it from GCC 6.1 onwards.