<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/131410>131410</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang 20 warns on nodiscard-call.static_member_function()
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          timsong-cpp
      </td>
    </tr>
</table>

<pre>
    Clang 20 started issuing warnings on code like

```cpp
struct mapping {
 static bool is_exhaustive();
};
template<class M>
struct mdspan {
 [[nodiscard]] M const& mapping() const;
};

void f() {
 mdspan<mapping> s;
    s.mapping().is_exhaustive();  // warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
}
```

Whatever the standard says about discarded-value expressions, warning on this code - basically a simplified `std::mdspan` - is undesirable. The actual `mapping()` member is marked nodiscard in at least one standard library implementation.

Not only is there nothing particularly wrong about calling a static member function like this, but here `is_exhaustive()` is a static member only as an implementation detail of the specific `mapping` class (in a different class, the result can depend on the state of `*this` and hence it needs to be non-static), so that it would be _wrong_ for the user to call it statically in generic code. There's also no easy way to suppress the warning. 

So the only way for the author of a template like this is to not mark `mapping()` as `[[nodiscard]]`. Which, it should go without saying, is rather unfortunate. `s.mapping();` should trigger a warning because the user probably meant something else.

This is presumably introduced by db93ef14aef9c572e02bc842762bc4d0278148f9. I'm surprised that the release notes change did not even mention the impact on warnings.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVUtv4zoP_TXKhkigyM5rkUWmnQLfYr7NHWCWBS3Rtu7IkqFHO_n3F5STPgYFArQwqEOew0MSU7KDJzqL3Texe1xhyWOI52ynFPyw1vO86oK5nh8c-gGUhJQxZjJgUyrWD_CK0Vs_JAgedDAEzv4mIS_828vlp-dZyEvKsegME84zPxSHb0JeGC9bDV0IDmx6pj8jlpTtCwl1FOokGo4Sh8fln0zT7DCTa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