1

在使用 mingw-w64 在 Ubuntu 16.04 for Windows 下交叉编译程序时,我遇到了这个错误。

考虑这个最小的示例程序 test.cc:

template <class E = void>
void call()
{
  auto l = [](auto&& cc) -> decltype(cc[0]) {};
}

int main()
{
  call<>();
}

使用 g++ 编译(版本 5.4.0)

g++ -std=c++14 test.cc -o test

工作正常,但是 mingw(版本 5.3.1)

x86_64-w64-mingw32-g++-posix -std=c++14 test.cc -o test

产生错误信息

test.cc: In instantiation of 'void call() [with E = void]':
test.cc:4:40: error: subscripted value is neither array nor pointer
    auto l = [](auto&& cc) -> decltype(cc[0]) {};
                                         ^

在上述示例函数中省略模板时,编译成功。

为什么 mingw 会为此表达式产生编译器错误?有没有办法重新制定表达式以避免此错误?

4

0 回答 0