| Issue |
178595
|
| Summary |
[clang-repl] treat top-level _expression_ evaluation as a "use" of nodiscard values
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
fogsong233
|
When using clang-repl, we often evaluate expressions to inspect their return values directly. For functions decorated with [[nodiscard]] (like `std::vector::size()`), this triggers a -Wunused-result warning, which clutters the output.
In the context of a REPL, the act of printing the result to the console is logically equivalent to "consuming" the value. Therefore, treating it as an "ignored result" is a false positive in terms of user intent.
Simply muting -Wunused-result globally feels too blunt as it might hide legitimate issues in nested code blocks. A more refined approach would be to implement a check in Sema to identify top-level expressions whose results are bound to the REPL's printing mechanism and treat them as "used."
Example
```bash
clang-repl> #include <vector>
clang-repl> auto v = std::vector<int>();
clang-repl> v.push_back(1);
clang-repl> v.size()
In file included from <<< inputs >>>:1:
input_line_4:1:1: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
1 | v.size()
| ^~~~~~~~
(unsigned long) 1
clang-repl>
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs