gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:05:11 26 4
gpt4 key购买 nike

我有以下 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

...

Pleasesubmit a full bug report, with preprocessed source if appropriate.

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com