【问题标题】:Why does structured binding fail on GCC?为什么结构化绑定在 GCC 上失败?
【发布时间】:2017-11-02 11:38:09
【问题描述】:

以下结构化绑定代码在 clang 上运行良好。 Live demo

但是,它在 GCC 编译器上失败了。 Live demo

#include <iostream>

struct st {
  bool b = true;
};

template <class T>
bool func() noexcept {
  auto [a] = T{};
  return a;
}

int main() {
  const bool b1 = func<st>();
}

为什么结构化绑定在 GCC 上会失败?

【问题讨论】:

  • 什么是预期结果,什么是实际结果?
  • 因为 GCC 在其实现中存在需要修复的错误。这就是你问的问题的答案。这不是一个过于有用的问题。但是,您可以改写它以使其更有用。
  • 这个问题...与 gcc 错误密切相关?
  • 编译器说“失败”?

标签: c++ gcc structure c++17


【解决方案1】:

这是在 GCC 7.2 中引入的known bug in GCC。您的代码符合标准。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    相关资源
    最近更新 更多