【发布时间】:2018-04-27 05:36:37
【问题描述】:
我正在调查为什么这段代码可以在我的具有 GCC v7.2 的 PC 上编译,但不能使用我们工具链的 GCC v5.4 进行编译,因为 -std=c++14 -Wpedantic -pedantic-errors 被传递:
#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 }
}
};
错误是:
<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}]'
};
^
这段代码是 C++14 有效的 (explanation),所以根据 GCC's Standards Support 页面——它显示了自 GCC v5 以来的完整 C++14 支持——我希望 GCC v5.4 能够编译它。
但是网上有人告诉我,这个GCC版本的编译器貌似支持C++14,但是附带的libstdc++不兼容C++14。
我的相关问题是:
- 最早提供 C++14 兼容 libstdc++ 的 GCC 版本是什么?对于其他标准,我如何也能发现这一点?
- 为什么 GCC 会宣传它对 gcc 版本具有 C++14 支持,而随附的 libstdc++ 却没有?
- 这是否表明 gcc 编译器可以与其他 stdlib 实现一起使用?
【问题讨论】:
-
(1) Wandbox 有多个 GCC 版本,您可以尝试二进制搜索。 (2) 人会犯错。根据 GPL,他们并不真正承担责任。
-
@rsp - 这个链接就在帖子里……
-
@StoryTeller 谢谢,看起来它最早可以在 GCC v6.1 下编译。但此代码仅检查 C++14 更改的一小部分。我想知道是否会宣布某些 libstdc++ 版本完全兼容(在合理程度上),因为我需要决定哪个版本将在我们的工具链中,以便用 C++14 编写我们的项目。
-
@DBedrenko - 我认为这没有灵丹妙药。您将不得不接受 GCC 版本并希望获得最好的结果。如果您的工具不能经常更改,您将不得不在某些时候使用变通方法进行编程。
标签: c++ gcc c++14 standards-compliance