[英]clang: Fold expression and “expression result unused” warning
On clang 7.0 this code: 在clang 7.0上,此代码:
template <typename ... Ts> struct S {
unsigned gs(unsigned i) {
unsigned r = 0;
((r = unsigned(sizeof(Ts)), i-- == 0) || ...);
return r;
}
};
int foo(unsigned i) {
S<int, double, long, float, char> s;
return s.gs(3);
}
causes this warning: 导致此警告:
~/dev/ta $ ~/bin/clang++ -c -std=c++17 fold-warning.cpp
fold-warning.cpp:5:46: warning: expression result unused [-Wunused-value]
((r = unsigned(sizeof(Ts)), i-- == 0) || ...);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
Why? 为什么? What expression is unused, by the compiler's logic?
编译器的逻辑未使用什么表达式?
Gcc 7.3/8.2 is happy with it. Gcc 7.3 / 8.2对此感到满意。
The result of this line: 该行的结果:
((r = unsigned(sizeof(Ts)), i-- == 0) || ...);
is a sequential ||
是顺序的
||
operation, whose result is not used, which caused the warning. 操作,其结果未使用,从而引起警告。
Casting to void
to eliminate the warning: 铸造到
void
消除警告:
(void)((r = unsigned(sizeof(Ts)), i-- == 0) || ...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.