8

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?
DBedrenko
  • 4,871
  • 4
  • 38
  • 73

1 Answers1

7

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.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • 2
    Thank you for the answer! I'm learning so much! But if I used a C++17 feature, why didn't the v6.1 compiler tell me this even though [I compiled](https://wandbox.org/permlink/yrXTalUUcyuvMwSn) with `-std=c++14 -pedantic-errors -pedantic`? I asked it to compile against a specific standard. – DBedrenko Nov 14 '17 at 11:43
  • 3
    Because the changes from the N4387 proposal fix a defect in the earlier standards ([LWG 2051](https://wg21.link/lwg2051)), so libstdc++ implements the fix unconditionally, for all standards modes. The point is that the change to fix that defect happened after C++14 was published, and after GCC 5 was released. For the change to be supported by GCC 5 would either require time travel, or backporting extremely invasive changes to a stable release branch. – Jonathan Wakely Nov 14 '17 at 12:52