我有以下 C++11 代码;
template<typename... T>
int g(T... t)
{
return 0;
}
template<class... Args>
void f(Args... args)
{
auto lm = [&, args...] { return g(args...); };
lm();
}
int main()
{
f(2, 5, 7);
}
根据,我确实相信它是有效的 C++11;标准第5.1.2.23条;
省略号后的捕获是包扩展 (14.5.3)。[ 例子:
template<class... Args> void f(Args... args) { auto lm = [&, args...] { return g(args...); }; lm(); }
—结束示例]
然而,虽然 Clang++ 编译得很好,但 G++ 提供了这个错误;
main.cpp: In function 'void f(Args ...)':
main.cpp:10:23: error: expected ',' before '...' token
auto lm = [&, args...] { return g(args...); };
^
main.cpp:10:23: error: expected identifier before '...' token
main.cpp:10:26: error: parameter packs not expanded with '...':
auto lm = [&, args...] { return g(args...); };
^
main.cpp:10:26: note: 'args'
main.cpp: In lambda function:
main.cpp:10:43: error: expansion pattern 'args' contains no argument packs
auto lm = [&, args...] { return g(args...); };
^
main.cpp: In instantiation of 'struct f(Args ...) [with Args = {int, int, int}]::__lambda0':
main.cpp:10:49: required from 'void f(Args ...) [with Args = {int, int, int}]'
main.cpp:16:14: required from here
main.cpp:10:19: error: using invalid field 'f(Args ...)::__lambda0::__args'
auto lm = [&, args...] { return g(args...); };
^
所以我的问题很简单,这是 G++ 中的编译器错误吗?