[clang-repl] treat top-level expression evaluation as a "use" of nodiscard values
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
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>
@fogsong233 can i work on this ??
@fogsong233 pls find the PR #178661 for this issue.