c++ - GCC 导致 lambda 捕获的参数包的段错误

标签 c++ gcc lambda

我有以下 SSCCE:

#include <iostream>
#include <string>

void foo(const std::string &a) {
  std::cout << a << std::endl;
}

template <typename... Args>
void bar(Args &&... args) {
  [&]() {
    [&]() {
          foo(args...);
      }();
  }();
}

int main() {
 const std::string x("Hello World!");
 bar(x);
}

在 clang++ (3.9.1) 下编译并发出“Hello World”。 Gcc 6.3 在 -O3 下因段错误而失败。

我可以通过引用显式传递指针和包来解决问题,将 [&]() 替换为 [&args...]()。但是,到目前为止,我认为 [&] 与将所有参数一一列出一样。

那么这里出了什么问题?

附注: 这不限于 -O3-O0 没有段错误但没有返回预期的结果(“Hello World!”):

[:~/tmp] $ g++-6 -std=c++1z param.cpp && ./a.out

[:~/tmp] $

P.P.S:进一步降低 SSCCE。现在我什至不再使用 -Wall -Wextra 进行诊断了。

最佳答案

我强烈怀疑存在 g++ 错误


这里有一些注意事项:

internal compiler error: in make_decl_rtl, at varasm.c:1304

...

Please submit a full bug report, with preprocessed source if appropriate.

Please include the complete backtrace with any bug report. See http://gcc.gnu.org/bugs.html for instructions.

关于c++ - GCC 导致 lambda 捕获的参数包的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41769851/

相关文章:

c++ - Mac OS X 链接器

c++ - 插入 map 未正确排序

c++ - 在 GCC 上构建的函数多重定义链接器错误 - Makefile 问题

gcc - GCC 选项 "-Wl,OPTION"中的 OPTION 是什么?

python - scipy.optimize 的最小化函数到底是如何工作的?

java - 在 Spock 中将 Lambda 函数定义为参数约束

c++ - do_ 未在此范围内声明

c++ - G++ 如何在 Linux 服务器上为 FreeBSD 编译

c++ - 编译器(GCC)如何处理 C++ 的访问控制?

java - optional ifPresent 调用对象方法