在C++可变参数lambda中使用"auto"关键字?

Ber*_*ard 0 c++ lambda variadic-templates auto c++14

我最近发现这段代码在GCC和MSVC中编译得很好:

auto foo = [](...){
    cout << "foo() called" << endl;
};
Run Code Online (Sandbox Code Playgroud)

它接受任意数量的任何参数,并且对这些参数没有任何作用,因此它就好像auto被放置在...:

// All of these lines will call the lambda function
foo();
foo(100);
foo("Test");
foo("Testing", 1, 2, 3);
Run Code Online (Sandbox Code Playgroud)

关于lambda函数的C++参考似乎没有提到这一点,参数包上的页面也没有提及.

更令人惊讶的是,这无法编译:

auto foo = [](... x){ // compile error
    cout << "foo() called" << endl;
};
Run Code Online (Sandbox Code Playgroud)

这种行为是否由标准规定,如果是这样,为什么前者编译而后者失败?

yur*_*hek 9

这只是普通的旧类型 - 不安全的C风格可变参数.