<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/131458>131458</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang: regression - erroneous warning when calling `[[nodiscard]]` `static` function through a `std::forward`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
elbeno
</td>
</tr>
</table>
<pre>
This code:
```cpp
#include <utility>
struct A {
[[nodiscard]] static auto f() {
return 42;
}
};
template <typename T>
auto f(T &&t) {
return std::forward<T>(t).f();
}
auto b = f(A{}) == 42;
```
https://godbolt.org/z/cxGvxM9bn
Provokes a warning:
```console
<source>:11:12: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
11 | return std::forward<T>(t).f();
| ^~~~~~~~~~~~~~~ ~
<source>:14:10: note: in instantiation of function template specialization 'f<A>' requested here
14 | auto b = f(A{}) == 42;
| ^
1 warning generated.
```
This seems to be a regression from clang-19.
This happens when:
- the function called is `static`
- we are calling it through member syntax with an object that is `std::forward`-ed
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVE2P8jYQ_jXmMgIldj7gkEMWXnqq1MNKPTvOkLg1dmqPYfc97G-vnLAsu91KVS1khJmZ52PGliHowSI2rHxi5WElI43ON2g6tG7Vuf61eR51AOV6ZKJlWcuqbPmoaUo_udBWmdgjMLGPpI2mVyZ-pL-yNpCPiqAFVj-xrAUAmIGerOt1UNL3rDyw8gCBJGkFMpKDE-NbxncPOWl5pOgtFJyJe6n6kGDqw3LEspbwPBlJMxd6ndDKM8LzQude-xkYrxiv6DPIDSBQn4SK9uT8NREU-7kA36b4zY3cDXEhcKvdAROHGaFNVevDXF8c0uk77bt7S95INIUEx4-MHwfXd87QxvmB8eNPxo_q5ZfLy6-7zi7hv3l3cX9iAAlX6a22w9eeOBucwXQk9sFFrzBxF22ep40z0T5kgh6s89oO79ov0kQEd4JTtIq0s9CjMtJjD1dNIzBefzSO1yCJvO5i8rt8Wv8ebQzYrz2GaCg1djY2z4HV-_9j79L4lPywWPnj7dOCt2_kFmnLkkbrCGetFrQNJC1pOUt7lHmfmzCh0tLon0sM4_WJiX07M6zB418RA2EPI3q8yStmhv95Ar4Rxco0n_l7Z2BAi14S9pt_Tsx8GwPiOUACRJDgcfAYQuJ78u4Mykg7rPPd5iFjlNOENsB1RLvMDKyBRvywQEljsAcdgFXZch0XUFjDFUF6nEMSP01Ao3dxGOGM5w49hFdL8mUZEmnBdX-gSkGS7gW_tL3K1tiv-kb0O7GTK2zyuuBZycuyWo0NFkVWF6rbnmSRo8p5rnb1FrHq-1zkJ7XSDc94mYm8zEu-y6vNbrfFqqu6rsjrrDxlrMjwLLXZGHM5pxu10iFEbHKRF-V2ZWSHJsyvHuezYYzz9AD6JiWsuzgEVmRGBwofJUiTwWYJF-2j8WtA751FF8O9jcnru2fJy-9ePlZlnwx_mMmbxfJf_FtFb5ovD4imMXYb5c6MHxPr29d68i51hPHj7EJg_Hgz4tLwvwMAAP__11vNcg">