具体来说,Clang 3.6.0,目前由 Coliru 托管。
所有这些片段都是从以下位置调用的:
int main() {
foo();
std::cout << "\n----\n";
foo(1, 2, 3);
}
以下代码:
template <class... Args>
void foo(Args... args) {
std::cout << ... << args;
}
触发以下编译错误:
main.cpp:7:17: error: expected ';' after expression
std::cout << ... << args;
^
;
main.cpp:7:15: error: expected expression
std::cout << ... << args;
^
所以我尝试在表达式两边加上括号:
(std::cout << ... << args);
它有效,但会触发警告:
main.cpp:7:6: warning: expression result unused [-Wunused-value]
(std::cout << ... << args);
^~~~~~~~~
main.cpp:11:5: note: in instantiation of function template specialization 'foo<>' requested here
foo();
^
所以我尝试用函数风格的强制转换来丢弃表达式的值void
:
void(std::cout << ... << args);
But :
main.cpp:7:20: error: expected ')'
void(std::cout << ... << args);
^
main.cpp:7:9: note: to match this '('
void(std::cout << ... << args);
^
我尝试了一个static_cast
也是为了同样的结果。
所以我尝试用 C-cast 代替:
(void)(std::cout << ... << args);
但是之后 :
main.cpp:6:18: warning: unused parameter 'args' [-Wunused-parameter]
void foo(Args... args) {
^
...我的输出只是----
: foo(1, 2, 3);
不再输出了!
Clang 是否受到未来标准中的邪恶力量的诅咒,它是否有错误,或者问题就在我的椅子上?