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

Why does structured binding fail on GCC?

以下结构化绑定代码在 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 7.2 中引入的 known bug in GCC。您的代码符合标准。