【发布时间】:2017-05-10 13:56:41
【问题描述】:
考虑:
struct Point { int x, y; };
int main()
{
const auto [x, y] = Point{};
}
这段代码在 C++17 模式下使用 gcc 7.1 编译得很好,但是这个:
#include <utility>
struct Point { int x, y; };
int main()
{
const auto [x, y] = Point{};
}
给出一个错误:
bug.cpp: In function 'int main()':
bug.cpp:7:16: error: 'std::tuple_size<const Point>::value' is not an integral constant expression
const auto [x, y] = Point{};
^~~~~~
这里发生了什么?一个编译器错误,或者这是结构化绑定应该如何工作的?
【问题讨论】:
-
我刚刚测试过,clang 4.0.0 的行为方式相同。
-
在最近的 Kona 会议 (2017-02-27 - 2017-03-04) 中,这方面似乎发生了变化。此功能还不成熟。
标签: c++ gcc c++17 structured-bindings gcc7