【发布时间】:2018-10-06 11:37:42
【问题描述】:
我一直致力于将我们的代码库迁移到 C++17,现在可以在本地使用 g++ 和 clang。
但是,我在 Travis 上遇到了 Clang 6.0 和 Clang 5.0 的编译失败,这两个版本都应该支持 C++17。
此外,在我的机器上使用 Clang 6.0 编译相同的代码成功。
失败的相关代码是通过大括号初始化返回一个元组,例如:
return {str.str(), key};
我得到的具体错误信息是:
/home/travis/build/turtlecoin/turtlecoin/src/Mnemonics/Mnemonics.cpp:51:20: error: chosen constructor is explicit in copy-initialization
return {str.str(), key};
^~~~~~~~~~~~~~~~ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/tuple:539:19: note: explicit constructor declared here
constexpr tuple(_U1&& __a1, _U2&& __a2)
它似乎按预期使用了 clang-6.0:
-- Check for working C compiler: /usr/bin/clang-6.0
-- Check for working C compiler: /usr/bin/clang-6.0 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++-6.0
-- Check for working CXX compiler: /usr/bin/clang++-6.0 -- works
我当地的 clang 工作正常:
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
这是 Travis 的问题吗?铛?我的代码?
如果有帮助,完整的构建日志在这里: https://travis-ci.org/turtlecoin/turtlecoin/jobs/437857481
编辑:忘了提 - 我在我的 CMakeLists 中使用标志来启用 C++17 模式:
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
谢谢。
【问题讨论】:
-
在此处查看 Notes 和 Defect Reports 中的示例:en.cppreference.com/w/cpp/utility/tuple/tuple 看起来还有一种解决方法。
-
@RichardCritten 当然我可以使用 std::make_tuple() - 这是我以前使用的。但是,我发现新语法更具可读性,并且希望利用 C++17 的特性。我不擅长解析 C++ 报告,但看起来他们正在用这些新功能修改 C++11 标准,而不是 C++17 标准?