On clang 7.0 this code:
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.
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)((r = unsigned(sizeof(Ts)), i-- == 0) || ...);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.