当我尝试制作可变参数 lambda 时:
#include <cstdarg>
int main() {
[] (int x, ...) { va_list xs; va_start(xs, x); va_end(xs); };
return 0;
}
使用 GCC 可以正常编译,但 clang 拒绝它:
main.cpp:4:35: error: 'va_start' used in function with fixed args [] (int x, ...) { va_list xs; va_start(xs, x); va_end(xs); }; ^
Which compiler is correct here? Is it possible to make a variadic lambda?
Curiously, the following results in an ICE with clang, so it looks like clang is being buggy with variadics:
int f(...) {
[] (int x, ...) { va_list xs; va_start(xs, x); va_end(xs); };
return;
}
最佳答案
似乎允许使用可变参数 lambda - 指定参数的语法与任何其他函数声明使用的 parameter-declaration-clause 相同,并且没有特定规则禁止它以省略。 (C++11 确实禁止默认参数,但不禁止省略号,并且在 C++14 中删除了该限制。)
无论如何,如果存在内部编译器错误(我假设这就是您所说的 ICE),那么这意味着编译器存在错误,无论代码的正确性如何。
关于c++ - 如何制作可变参数 lambda?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29231601/