Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?
like image 597
DBedrenko Avatar asked Nov 14 '17 10:11

DBedrenko


People also ask

Does GCC support the C++14 standard?

GCC has full support for the of the 2014 C++ standard. This mode is the default in GCC 6.1 up until GCC 10 (including); it can be explicitly selected with the -std=c++14 command-line flag, or -std=gnu++14 to enable GNU extensions as well. The following table lists new language features that are part of the C++14 standard.

Which version of C is supported by GCC?

A fourth version of the C standard, known as C11, was published in 2011 as ISO/IEC 9899:2011. (While in development, drafts of this standard version were referred to as C1X.) GCC has substantially complete support for this standard, enabled with -std=c11 or -std=iso9899:2011.

When did GCC start using ANSI C?

For each language compiled by GCC for which there is a standard, GCC attempts to follow one or more versions of that standard, possibly with some exceptions, and possibly with some extensions. The original ANSI C standard (X3.159-1989) was ratified in 1989 and published in 1990.

Does GCC support C++20?

GCC has experimental support for the latest revision of the C++ standard, which was published in 2020. C++20 features are available since GCC 8. To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line.


1 Answers

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.

like image 93
Jonathan Wakely Avatar answered Oct 12 '22 12:10

Jonathan Wakely