Issue 140205
Summary Unnecessary -Wunused-value warning for fold _expression_ with empty pack
Labels new issue
Assignees
Reporter svensandberg
    The fold _expression_ in the following program produces the warning `_expression_ result unused [-Wunused-value]` (https://godbolt.org/z/715deezdG) in clang 5.0.0 and up (verified on 20.0.1):
```
#include <iostream>
#include <sstream>

template <class... Args>
std::string concat(Args &&...args) {
  std::ostringstream out;
 (out << ... << args);
  return out.str();
}

int main() {
    std::cout << concat();
}
```
I assume the reason is that when no arguments are passed to the function, the fold _expression_ reduces to the _expression_ `(out)`. If we had used the syntax `(out)` alone, the warning would be valid. But this code is meaningful when passing arguments to the function, and it would be useful to allow no arguments without warnings.
Workaround: `std::ignore = (out << ... << args)`.
Similar: https://github.com/llvm/llvm-project/issues/45124

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to